{"id":136,"date":"2010-02-28T03:00:00","date_gmt":"2010-02-27T19:00:00","guid":{"rendered":"http:\/\/localhost\/?p=136"},"modified":"2023-01-30T20:12:50","modified_gmt":"2023-01-30T20:12:50","slug":"topcoder_higschool_2010_round_1","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/wjmzbmr\/?p=136","title":{"rendered":"TopCoder HigSchool 2010 Round 1"},"content":{"rendered":"<p> \u8fd9\u662f\u7b2c\u4e00\u6b21\u6bd4\u8d5b\u3002\u3002\u672c\u6765\u662f\u6d77\u9009\u51fa500\u4e2a\u4eba\u7684\u3002\u3002\u7ed3\u679c\u603b\u5171\u90fd\u6ca1\u6709500\u4e2a\u4eba\u56e7\u3002\u3002<br \/>\u7531\u4e8e\u660e\u5929\u5c31\u8981\u4e0a\u5b66\u4e86\u3002\u3002\u672c\u6765\u4e0d\u60f3\u53c2\u52a0\u7684\u3002\u3002\u4f46\u662f\u6839\u672c\u6ca1\u6709\u7761\u610f\u3002\u3002\u4e8e\u662f\u5c31\u4e0a\u4e86\u3002\u3002<br \/>\u7b2c\u4e00\u9898\u8fd9\u4e2a\u592a\u6c34\u4e86\u3002\u3002\u600e\u4e48\u505a\u90fd\u53ef\u4ee5\u3002\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;vector&gt;\r\n#include &lt;list&gt;\r\n#include &lt;map&gt;\r\n#include &lt;set&gt;\r\n#include &lt;deque&gt;\r\n#include &lt;stack&gt;\r\n#include &lt;bitset&gt;\r\n#include &lt;algorithm&gt;\r\n#include &lt;functional&gt;\r\n#include &lt;numeric&gt;\r\n#include &lt;utility&gt;\r\n#include &lt;sstream&gt;\r\n#include &lt;iostream&gt;\r\n#include &lt;iomanip&gt;\r\n#include &lt;cstdio&gt;\r\n#include &lt;cmath&gt;\r\n#include &lt;cstdlib&gt;\r\n#include &lt;ctime&gt;\r\n\r\nusing namespace std;\r\n\r\nclass TheSequencesLevelOne\r\n{\r\npublic:\r\n    vector &lt;int&gt; find(vector &lt;int&gt;);\r\n};\r\n\r\nvector &lt;int&gt; TheSequencesLevelOne::find(vector &lt;int&gt; s)\r\n{\r\n    vector&lt;int&gt; ans;\r\n    for(int i=0; i&lt;s.size(); i++)\r\n    {\r\n        int a;\r\n        for(int t=0; t&lt;=7; t++)\r\n        {\r\n            int x=s[i];\r\n            x-=t;\r\n            if(x%4==0||x%7==0)\r\n            {\r\n                a=x;\r\n                break;\r\n            }\r\n            x+=2*t;\r\n            if(x%4==0||x%7==0)\r\n            {\r\n                a=x;\r\n                break;\r\n            }\r\n        }\r\n        ans.push_back(a);\r\n    }\r\n    return ans;\r\n}\r\n\r\n\/\/Powered by [KawigiEdit] 2.0!\r\n<\/pre>\n<p>\u7b2c\u4e8c\u9898\u627e\u89c4\u5f8b\u554a\u3002\u3002\u5947\u6570\u4f4d\u653e\u5f53\u524d\u6700\u5c0f\u7684\uff0c\u653e\u4e86\u540e\u5220\u6389\uff0c\u5076\u6570\u4f4d\u653e\u5f53\u524d\u7b2c\u4e8c\u5c0f\u7684\uff0c\u653e\u4e86\u540e\u5220\u6389\uff0c<br \/>\u6700\u540e\u4e00\u4f4d\u7279\u5224\u4e00\u4e0b\u5c31\u53ef\u4ee5\u4e86\u3002\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;vector&gt;\r\n#include &lt;list&gt;\r\n#include &lt;map&gt;\r\n#include &lt;set&gt;\r\n#include &lt;deque&gt;\r\n#include &lt;stack&gt;\r\n#include &lt;bitset&gt;\r\n#include &lt;algorithm&gt;\r\n#include &lt;functional&gt;\r\n#include &lt;numeric&gt;\r\n#include &lt;utility&gt;\r\n#include &lt;sstream&gt;\r\n#include &lt;iostream&gt;\r\n#include &lt;iomanip&gt;\r\n#include &lt;cstdio&gt;\r\n#include &lt;cmath&gt;\r\n#include &lt;cstdlib&gt;\r\n#include &lt;ctime&gt;\r\n\r\nusing namespace std;\r\n\r\nclass TheSequencesLevelTwo\r\n{\r\npublic:\r\n    vector &lt;int&gt; find(vector &lt;int&gt;);\r\n};\r\n\r\nvector &lt;int&gt; TheSequencesLevelTwo::find(vector &lt;int&gt; s)\r\n{\r\n    set&lt;int&gt; S(s.begin(),s.end());\r\n    vector&lt;int&gt; Ans;\r\n    for(int i=0; i&lt;s.size()-1; i++)\r\n    {\r\n        if(i%2==0)\r\n        {\r\n            Ans.push_back(*S.begin());\r\n            S.erase(S.begin());\r\n        }\r\n        else\r\n        {\r\n            Ans.push_back(*(++S.begin()));\r\n            S.erase(++S.begin());\r\n        }\r\n    }\r\n    Ans.push_back(*S.begin());\r\n    return Ans;\r\n}\r\n\r\n\/\/Powered by [KawigiEdit] 2.0!\r\n\r\n<\/pre>\n<p>\u7b2c\u4e09\u9898\u7684\u9898\u76ee\u53ef\u4ee5\u8f6c\u5316\u6210\u5206\u6210\u6709\u5e8f\u7684\u4e24\u5806\u4e0d\u5305\u62ec\u6700\u5927\u6570\uff0c\u4e24\u5806\u4e2d\u76f8\u90bb\u5143\u7d20\u5dee\u4e0d\u8d85\u8fc7K\u3002\u90a3\u4e48\u4ece\u5c0f\u5230\u5927\u4e00\u4e2a\u4e2a\u8003\u8651\u5143\u7d20\uff0c\u6bcf\u4e2a\u5806\u6709\u610f\u4e49\u7684\u53ea\u6709\u5927\u5c0f\u548c\u6700\u4e0a\u9762\u7684\u6570\u3002\u3002\u540c\u65f6\u4e00\u5b9a\u6709\u4e00\u4e2a\u5806\u6700\u4e0a\u9762\u662f\u5f53\u524d\u6700\u5927\u7684\u6570\uff0c\u6240\u4ee5\u53ea\u8981\u8bb0\u5f553\u4e2a\u503c\u5c31\u53ef\u4ee5\u4e86\u3002\u3002\u7136\u540e\u9012\u63a8\u3002\u3002\u7b97\u51fa\u6240\u6709\u7684\u7ed3\u679c\u3002\u3002\u7136\u540e\u5224\u65ad\u4e00\u4e0b\u6700\u5927\u6570\u5c31\u53ef\u4ee5\u4e86\u3002\u3002<br \/>\u6211\u4e5f\u4e0d\u77e5\u9053\u4e3a\u4ec0\u4e48\u6211\u975e\u5e38WS\u7684\u7528\u4e86\u52a8\u6001\u7533\u8bf7\u3002\u3002<br \/>dp[i][j][k]\u5f53\u524d\u5de6\u8fb9\u5806\u6709i\u4e2a\uff0c\u53f3\u8fb9\u5806\u6709j\u6700\u5927\u7684\u90a3\u4e2a\u5728\u5de6\u8fb9\u5806\u7684\u6700\u4e0a\u9762\uff0ck\u662f\u53f3\u8fb9\u5806\u6700\u4e0a\u9762\u6570\u7684\u7f16\u53f7<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;vector&gt;\r\n#include &lt;list&gt;\r\n#include &lt;map&gt;\r\n#include &lt;set&gt;\r\n#include &lt;deque&gt;\r\n#include &lt;stack&gt;\r\n#include &lt;bitset&gt;\r\n#include &lt;algorithm&gt;\r\n#include &lt;functional&gt;\r\n#include &lt;numeric&gt;\r\n#include &lt;utility&gt;\r\n#include &lt;sstream&gt;\r\n#include &lt;iostream&gt;\r\n#include &lt;iomanip&gt;\r\n#include &lt;cstdio&gt;\r\n#include &lt;cmath&gt;\r\n#include &lt;cstdlib&gt;\r\n#include &lt;ctime&gt;\r\n\r\nusing namespace std;\r\n\r\nclass TheSequencesLevelThree\r\n{\r\npublic:\r\n    int find(vector &lt;int&gt;, int);\r\n};\r\nconst int mod=1234567891;\r\nint TheSequencesLevelThree::find(vector &lt;int&gt; s, int K)\r\n{\r\n    sort(s.begin(),s.end());\r\n    long long***dp;\r\n    int n=s.size();\r\n    if(n&lt;3) return 0;\r\n    dp=new long long**[n+1];\r\n    for(int i=0; i&lt;=n; i++)\r\n    {\r\n        dp[i]=new long long*[n+1];\r\n        for(int j=0; j&lt;=n; j++)\r\n        {\r\n            dp[i][j]=new long long[n+1];\r\n            for(int k=0; k&lt;=n; k++)\r\n                dp[i][j][k]=0;\r\n        }\r\n    }\r\n    dp[0][0][0]=1;\r\n    int t;\r\n    for(int l=0; l&lt;n; l++)\r\n        for(int i=0; i&lt;=l; i++)\r\n        {\r\n            int j=l-i;\r\n            for(int k=0; k&lt;n; k++)\r\n                if(t=dp[i][j][k])\r\n                {\r\n                    int now=i+j;\r\n                    if(i==0||s[now]-s[now-1]&lt;=K)\r\n                        dp[i+1][j][k]+=t,dp[i+1][j][k]%=mod;\r\n                    if(j==0||s[now]-s[k]&lt;=K)\r\n                        dp[j+1][i][now-1]+=t,dp[j+1][i][now-1]%=mod;\r\n                }\r\n        }\r\n    long long ans=0;\r\n    for(int l=1; l&lt;n-1; l++)\r\n    {\r\n        int r=n-l-1;\r\n        for(int k=0; k&lt;n; k++)\r\n        {\r\n            int x=dp[l][r][k];\r\n            if(s[n-1]-s[k]&lt;=K&amp;&amp;s[n-1]-s[n-2]&lt;=K)\r\n                ans+=x,ans%=mod;\r\n        }\r\n    }\r\n    ans*=2;\r\n    ans%=mod;\r\n    return ans;\r\n}\r\n\r\n\/\/Powered by [KawigiEdit] 2.0!\r\n\r\n<\/pre>\n<p>\u6211\u8fd8Cha\u6389\u4e86\u4e00\u4e2a\u4eba\u7684\u7a0b\u5e8f\u3002\u3002\u7b97\u6cd5\u4e0d\u77e5\u9053\u5bf9\u4e0d\u5bf9\u3002\u4e00\u770b\u4ed6\u7684\u7279\u5224\u5c31\u77e5\u9053\u4ed6\u5224\u9519\u4e86\u3002\u3002\u5904\u5973Cha\u554a\u3002\u3002<br \/>\u6211\u7684Coding\u7684\u901f\u5ea6\u771f\u662f\u6162\u6b7b\u4e86\u3002\u3002\u5206\u4f4e\u7684\u8981\u547d\u3002\u3002\u56e7<br \/>PS.\u90a3\u4e2a\u4eba\u7b97\u6cd5\u771f\u662f\u5bf9\u7684\u3002\u3002<br \/><img decoding=\"async\" src=\"http:\/\/wjmzbmr.com\/wp-content\/uploads\/pic\/35615c1352b9d724b8127b4d.jpg\" small=\"0\" class=\"blogimg\" \/><br \/>\u8fd9\u4e48\u5927\u7684\u968f\u673a\u6570\u636e\u90fd\u8fc7\u4e86\u3002\u3002\u53cd\u800c\u88ab\u6211\u8fd9\u4e2aCha\u6389\u56e7\u3002\u3002 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u662f\u7b2c\u4e00\u6b21\u6bd4\u8d5b\u3002\u3002\u672c\u6765\u662f\u6d77\u9009\u51fa500\u4e2a\u4eba\u7684\u3002\u3002\u7ed3\u679c\u603b\u5171\u90fd\u6ca1\u6709500\u4e2a\u4eba\u56e7\u3002\u3002\u7531\u4e8e\u660e\u5929\u5c31\u8981\u4e0a\u5b66\u4e86\u3002\u3002\u672c\u6765\u4e0d\u60f3\u53c2\u52a0\u7684\u3002\u3002\u4f46\u662f\u6839\u672c\u6ca1\u6709\u7761\u610f\u3002\u3002\u4e8e\u662f\u5c31\u4e0a\u4e86\u3002\u3002\u7b2c\u4e00\u9898\u8fd9\u4e2a\u592a\u6c34\u4e86\u3002\u3002\u600e\u4e48\u505a\u90fd\u53ef\u4ee5\u3002\u3002 \u7b2c\u4e8c\u9898\u627e\u89c4\u5f8b\u554a\u3002\u3002\u5947\u6570\u4f4d\u653e\u5f53\u524d\u6700\u5c0f\u7684\uff0c\u653e\u4e86\u540e\u5220\u6389\uff0c\u5076\u6570\u4f4d\u653e\u5f53\u524d\u7b2c\u4e8c\u5c0f\u7684\uff0c\u653e\u4e86\u540e\u5220\u6389\uff0c\u6700\u540e\u4e00\u4f4d\u7279\u5224\u4e00\u4e0b\u5c31\u53ef\u4ee5\u4e86\u3002\u3002 \u7b2c\u4e09\u9898\u7684\u9898\u76ee\u53ef\u4ee5\u8f6c\u5316\u6210\u5206\u6210\u6709\u5e8f\u7684\u4e24\u5806\u4e0d\u5305\u62ec\u6700\u5927\u6570\uff0c\u4e24\u5806\u4e2d\u76f8\u90bb\u5143\u7d20\u5dee\u4e0d\u8d85\u8fc7K\u3002\u90a3\u4e48\u4ece\u5c0f\u5230\u5927\u4e00\u4e2a\u4e2a\u8003\u8651\u5143\u7d20\uff0c\u6bcf\u4e2a\u5806\u6709\u610f\u4e49\u7684\u53ea\u6709\u5927\u5c0f\u548c\u6700\u4e0a\u9762\u7684\u6570\u3002\u3002\u540c\u65f6\u4e00\u5b9a\u6709\u4e00\u4e2a\u5806\u6700\u4e0a\u9762\u662f\u5f53\u524d\u6700\u5927\u7684\u6570\uff0c\u6240\u4ee5\u53ea\u8981\u8bb0\u5f553\u4e2a\u503c\u5c31\u53ef\u4ee5\u4e86\u3002\u3002\u7136\u540e\u9012\u63a8\u3002\u3002\u7b97\u51fa\u6240\u6709\u7684\u7ed3\u679c\u3002\u3002\u7136\u540e\u5224\u65ad\u4e00\u4e0b\u6700\u5927\u6570\u5c31\u53ef\u4ee5\u4e86\u3002\u3002\u6211\u4e5f\u4e0d\u77e5\u9053\u4e3a\u4ec0\u4e48\u6211\u975e\u5e38WS\u7684\u7528\u4e86\u52a8\u6001\u7533\u8bf7\u3002\u3002dp[i][j][k]\u5f53\u524d\u5de6\u8fb9\u5806\u6709i\u4e2a\uff0c\u53f3\u8fb9\u5806\u6709j\u6700\u5927\u7684\u90a3\u4e2a\u5728\u5de6\u8fb9\u5806\u7684\u6700\u4e0a\u9762\uff0ck\u662f\u53f3\u8fb9\u5806\u6700\u4e0a\u9762\u6570\u7684\u7f16\u53f7 \u6211\u8fd8Cha\u6389\u4e86\u4e00\u4e2a\u4eba\u7684\u7a0b\u5e8f\u3002\u3002\u7b97\u6cd5\u4e0d\u77e5\u9053\u5bf9\u4e0d\u5bf9\u3002\u4e00\u770b\u4ed6\u7684\u7279\u5224\u5c31\u77e5\u9053\u4ed6\u5224\u9519\u4e86\u3002\u3002\u5904\u5973Cha\u554a\u3002\u3002\u6211\u7684Coding\u7684\u901f\u5ea6\u771f\u662f\u6162\u6b7b\u4e86\u3002\u3002\u5206\u4f4e\u7684\u8981\u547d\u3002\u3002\u56e7PS.\u90a3\u4e2a\u4eba\u7b97\u6cd5\u771f\u662f\u5bf9\u7684\u3002\u3002\u8fd9\u4e48\u5927\u7684\u968f\u673a\u6570\u636e\u90fd\u8fc7\u4e86\u3002\u3002\u53cd\u800c\u88ab\u6211\u8fd9\u4e2aCha\u6389\u56e7\u3002\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/136"}],"collection":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=136"}],"version-history":[{"count":4,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/136\/revisions"}],"predecessor-version":[{"id":789,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/136\/revisions\/789"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}