{"id":661,"date":"2019-06-09T09:01:47","date_gmt":"2019-06-09T01:01:47","guid":{"rendered":"http:\/\/fankasy.xyz\/?p=661"},"modified":"2019-09-25T09:10:46","modified_gmt":"2019-09-25T01:10:46","slug":"noj1022-%e5%93%88%e5%a4%ab%e6%9b%bc%e7%bc%96%e7%a0%81%e4%b8%8e%e8%af%91%e7%a0%81","status":"publish","type":"post","link":"http:\/\/fankasy.xyz\/index.php\/2019\/06\/09\/noj1022-%e5%93%88%e5%a4%ab%e6%9b%bc%e7%bc%96%e7%a0%81%e4%b8%8e%e8%af%91%e7%a0%81\/","title":{"rendered":"NOJ1022 \u54c8\u592b\u66fc\u7f16\u7801\u4e0e\u8bd1\u7801"},"content":{"rendered":"<p>\u4ece\u8fd9\u5f00\u59cb\u6709\u4e9b\u7528C++\u91cd\u65b0\u5199\u4e86\uff01<\/p>\n<pre>#include&lt;iostream&gt;\r\n#include&lt;queue&gt;\r\n#include&lt;string&gt;\r\nusing namespace std;\r\n#define MAX 10\r\n \r\n \r\nchar str[8]={'A','C','I','M','N','P','T','U'};\r\nint temp[MAX*3];\r\nint str2[256][MAX*3];\r\nstring str3;\r\n \r\nclass node\r\n{\r\n    public:\r\n    int k;\r\n    char c;\r\n    node *l,*r;\r\n    node()\r\n    {\r\n        c='0';\r\n        k=0;r=l=NULL;\r\n    }\r\n    node(int a,char s)\r\n    {\r\n        k=a;r=l=NULL;\r\n        c=s;\r\n    }\r\n    friend node* uni(node *p,node *q)\r\n    {\r\n        node *temp=new node(p-&gt;k+q-&gt;k,'0');\r\n        temp-&gt;l=p;\r\n        temp-&gt;r=q;\r\n        return temp;\r\n    }\r\n};\r\nvoid prim(node *p,int L)\r\n{\r\n    if(!p-&gt;r)\r\n    {\r\n        str2[p-&gt;c][0]=L;\r\n        for(int i=1;i&lt;=L;i++) { str2[p-&gt;c][i]=temp[i-1];\r\n        }\r\n    }\r\n    else\r\n    {\r\n        temp[L]=0;\r\n        prim(p-&gt;l,L+1);\r\n        temp[L]=1;\r\n        prim(p-&gt;r,L+1);\r\n    }\r\n}\r\n \r\nclass nodeCmp\r\n{\r\npublic:\r\n    bool operator()(node* p1, node* p2) const\r\n    {\r\n        return p1-&gt;k &gt; p2-&gt;k;\r\n    }\r\n};\r\nnode *s[MAX*3];\r\npriority_queue,nodeCmp&gt; pro_queue;\r\nint main()\r\n{\r\n    \r\n    int i,a;\r\n    for(i=0;i&lt;8;i++) { cin&gt;&gt;a;\r\n        node *p;\r\n        p=new node(a,str[i]);\r\n        s[i]=p;\r\n        pro_queue.push(s[i]);\r\n    }\r\n    while(pro_queue.size()&gt;1)\r\n    {\r\n        node *p,*q,*k;\r\n        p=pro_queue.top();\r\n        pro_queue.pop();\r\n        q=pro_queue.top();\r\n        pro_queue.pop();\r\n        k=uni(p,q);\r\n        pro_queue.push(k);\r\n        }\r\n        node *p=pro_queue.top();\r\n        prim(p,0);\r\n        for(i=0;i&lt;8;i++)\r\n        {\r\n            cout&lt;&lt;str[i]&lt;&lt;\": \";\r\n            for(int j=1;j&lt;=str2[str[i]][0];j++)\r\n            {\r\n                cout&lt;&lt;str2[str[i]][j];\r\n                }\r\n                cout&lt;&lt;endl; } cin&gt;&gt;str3;\r\n            int len=str3.length();\r\n            for(i=0;i&lt;len;i++)\r\n            {\r\n                for(int j=1;j&lt;=str2[str3[i]][0];j++)\r\n                {\r\n                cout&lt;&lt;str2[str3[i]][j];\r\n                }\r\n            }\r\n            cout&lt;&lt;endl; cin&gt;&gt;str3;\r\n            len=str3.length();\r\n            node *q=pro_queue.top();\r\n            for(i=0;i&lt;len;i++) { if(str3[i]=='1') { q=q-&gt;r;\r\n                }\r\n                else\r\n                {\r\n                q=q-&gt;l;\r\n                }\r\n                if(q-&gt;c!='0')\r\n                {\r\n                cout&lt;c;\r\n                q=pro_queue.top();\r\n                }\r\n            }\r\n            cout&lt;&lt;endl;\r\n    return 0;\r\n    }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4ece\u8fd9\u5f00\u59cb\u6709\u4e9b\u7528C++\u91cd\u65b0\u5199\u4e86\uff01 #include&lt;iostream&gt; #include&lt;qu [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[],"_links":{"self":[{"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/posts\/661"}],"collection":[{"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=661"}],"version-history":[{"count":0,"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/posts\/661\/revisions"}],"wp:attachment":[{"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=661"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}