{"id":45,"date":"2016-05-23T18:15:41","date_gmt":"2016-05-23T10:15:41","guid":{"rendered":"http:\/\/tyswly.com\/?p=45"},"modified":"2016-05-23T18:15:41","modified_gmt":"2016-05-23T10:15:41","slug":"noip2004-%e5%90%88%e5%b9%b6%e6%9e%9c%e5%ad%90","status":"publish","type":"post","link":"https:\/\/tys.fun\/?p=45","title":{"rendered":"[NOIP2004] \u5408\u5e76\u679c\u5b50"},"content":{"rendered":"<p>\u539f\u9898\u53c2\u89c1<a href=\"http:\/\/cogs.pro\/cogs\/problem\/problem.php?pid=75\">COGS<\/a><br \/>\n\u8fd9\u9898\uff0c\u597d\u591a\u79cd\u89e3\u6cd5\u5462\u3002\u7136\u800c\u6211\u4e00\u76f4\u89c9\u5f97\u5192\u6ce1\u624d\u662f\u6700\u4f18\u7f8e\u7684\u5199\u6cd5\/\/\u5927\u96fe\u3002<br \/>\n\u987a\u5e26\u7ec3\u4e86\u4e00\u53d1\u5bf9\u62cd\u3002\u3002\u3002<\/p>\n<pre class=\"lang:c++ decode:true \">#include &lt;iostream&gt;\n#include &lt;cstdio&gt;\n#include &lt;algorithm&gt;\nusing namespace std;\nint n, num[10005];\nlong long ans;\nvoid swap2(int &amp;a, int &amp;b) {\n\tint t =a;\n\ta = b;\n\tb = t;\n}\nint get_num() {\n\tint ans = 0;\n\tchar tmp;\n\ttmp = getchar();\n\twhile (tmp &gt; '9' || tmp &lt; '0')\ttmp = getchar();\n\twhile (tmp &gt;= '0' &amp;&amp; tmp &lt;= '9') {\n\t\tans = ans * 10 + tmp - 48;\n\t\ttmp = getchar();\n\t}\n\treturn ans;\n}\nvoid he(int &amp;a, int &amp;b) {\n\tb += a;\n\ta = 0;\n}\nvoid buble(int cnt) {\n\tint i = cnt;\n\twhile (num[i] &gt; num[i + 1] &amp;&amp; i &lt; n) {\n\t\tswap2(num[i], num[i + 1]);\n\t\ti++;\n\t}\n}\nint main() {\n\tfreopen(\"fruit.in\", \"r\", stdin);\n\tfreopen(\"fruit.out\", \"w\", stdout);\n\tcin &gt;&gt; n;\n\tfor (int i = 1; i &lt;= n; i++) {\n\t\tnum[i] = get_num();\n\t}\n\tsort (num + 1, num + n + 1);\n\tfor (int i = 1; i &lt; n; i++) {\n\t\the(num[i], num[i+1]);\n\t\tans += num[i+1];\n\t\tbuble(i + 1);\n\t}\n\tcout &lt;&lt; ans &lt;&lt; endl;\n\treturn 0;\n}\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u9898\u53c2\u89c1COGS \u8fd9\u9898\uff0c\u597d\u591a\u79cd\u89e3\u6cd5\u5462\u3002\u7136\u800c\u6211\u4e00\u76f4\u89c9\u5f97\u5192\u6ce1\u624d\u662f\u6700\u4f18\u7f8e\u7684\u5199\u6cd5\/\/\u5927\u96fe\u3002 \u987a\u5e26\u7ec3\u4e86\u4e00\u53d1\u5bf9\u62cd\u3002\u3002\u3002 # &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-45","post","type-post","status-publish","format-standard","hentry","category-report"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/posts\/45","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tys.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=45"}],"version-history":[{"count":0,"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/posts\/45\/revisions"}],"wp:attachment":[{"href":"https:\/\/tys.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tys.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tys.fun\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}