{"id":350,"date":"2018-07-31T17:37:40","date_gmt":"2018-07-31T17:37:40","guid":{"rendered":"https:\/\/www.haoyuan.info\/?p=350"},"modified":"2018-07-31T17:37:40","modified_gmt":"2018-07-31T17:37:40","slug":"codeforces-round-501-div-3-%e9%a2%98%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/haoyuan.info\/?p=350","title":{"rendered":"Codeforces Round #501 (Div. 3) \u9898\u89e3"},"content":{"rendered":"<h2>Problem A Points in Segments<\/h2>\n<h3>\u9898\u610f<\/h3>\n<p>\u7ed9\u4f60\u82e5\u5e72\u4e2a\u533a\u95f4\uff0c\u4ee5\u53ca\u533a\u95f4\u5927\u5c0fn,\u95ee\u4f60\u5728\u533a\u95f4$$[1,n]$$\u5185\u6ca1\u6709\u88ab\u8986\u76d6\u7684\u70b9\u6709\u54ea\u4e9b\u3002<\/p>\n<h3>\u9898\u89e3<\/h3>\n<p>\u4e71\u641e\uff0c\u8303\u56f4\u4e0d\u5927<\/p>\n<pre><code class=\" line-numbers\">#include &lt;iostream&gt;\n#include &lt;algorithm&gt;\n#include &lt;cstring&gt;\n#include &lt;array&gt;\n#include &lt;vector&gt;\nusing namespace std;\nusing ll = long long;\nint arr[110];\nvector&lt;int&gt;ans;\nint main() {\n    int num, tot;\n    cin &gt;&gt; num &gt;&gt; tot;\n\n    for (int i = 0; i &lt; num; ++i) {\n        int s, e;\n        cin &gt;&gt; s &gt;&gt; e;\n        for (int j = s; j &lt;= e; ++j) {\n            arr[j] = 1;\n        }\n    }\n    int len = 0;\n    for(int i = 1;i&lt;=tot;++i) {\n        if(!arr[i]) {\n            ans.push_back(i);\n        }\n    }\n    cout &lt;&lt; (len = ans.size()) &lt;&lt; \"\\n\";\n    for(int i = 0;i&lt;len;++i) {\n        if(i)cout &lt;&lt; \" \";\n        cout &lt;&lt; ans[i];\n    }\n    cout &lt;&lt; \"\\n\";\n}\n<\/code><\/pre>\n<h2>Problem B &#8211; Obtaining the String<\/h2>\n<h3>\u9898\u610f<\/h3>\n<p>\u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32$$s,t$$\uff0c\u4f60\u53ef\u4ee5\u5bf9s\u4e32\u8fdb\u884c\u64cd\u4f5c\uff0c\u4f46\u4e0d\u80fd\u5bf9t\u4e32\u8fdb\u884c\u64cd\u4f5c\u3002<br \/>\n\u8bbe$$s$$\u4e32\u4e2d\u6bcf\u4e00\u4e2a\u5b57\u7b26\u4e3a$$s_i$$,\u6bcf\u4e00\u6b21\u53ef\u4ee5\u4ea4\u6362$$s_i$$\u548c$$s_j$$\u7684\u4f4d\u7f6e\u3002<br \/>\n\u95ee\u80fd\u5426\u5728$$10^4$$\u6b21\u64cd\u4f5c\u5185\u5b8c\u6210\u4ea4\u6362\u4f7f\u5f97$$s == t$$<br \/>\n$$1 \\leq|s| = |t| \\leq 50$$<br \/>\n\u7ed9\u51fa\u4efb\u610f\u4e00\u7ec4\u89e3<br \/>\n\u65e0\u89e3\u8f93\u51fa-1<\/p>\n<h3>\u9898\u89e3<\/h3>\n<p>\u4e4d\u770b\u597d\u50cf\u6ca1\u6709\u4ec0\u4e48\u5934\u7eea\uff0c\u5176\u5b9e\u53ef\u4ee5\u8d2a\u5fc3\u6765\u89e3\u51b3\u3002<br \/>\n\u4ece\u5de6\u5f80\u53f3\u626b\uff0c\u5982\u679c$$t[i] != s[i]$$,\u5c31\u627e\u4e00\u4e2a$$s[j] == t[i]$$,$$|j-i|=min$$ \u4ea4\u6362\u3002<br \/>\n\u8003\u8651\u5230\u4e0d\u6ee1\u8db3\u6761\u4ef6\u7684\u53ef\u80fd\u53ea\u6709\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5404\u4e2a\u5b57\u7b26\u96c6\u7684\u5bb9\u91cf\u4e0d\u7b49<br \/>\n\uff08\u5982abc\u4e0eabb\uff09,\u6240\u4ee5\u53ea\u8981\u5728\u5b57\u7b26\u96c6\u76f8\u540c\u7684\u60c5\u51b5\u4e00\u5b9a\u6709\u89e3<br \/>\n\u4e71\u641e\u4e00\u4e0b<\/p>\n<pre><code class=\" line-numbers\">#include &lt;iostream&gt;\n#include &lt;algorithm&gt;\n#include &lt;cstring&gt;\n#include &lt;array&gt;\n#include &lt;vector&gt;\nusing namespace std;\nusing ll = long long;\nint arr[110];\nvector&lt;int&gt;ans;\nint main() {\n    string s,t;\n    int len;\n    cin &gt;&gt; len;\n    cin &gt;&gt; s &gt;&gt; t;\n    string cs,ct;\n    cs = s,ct = t;\n    sort(cs.begin(),cs.end());\n    sort(ct.begin(),ct.end());\n    if(cs != ct) {\n        cout &lt;&lt; -1 &lt;&lt; \"\\n\";\n    }\n    else {\n        for (int i = 0; i &lt; len; ++i) {\n            if (s[i] == t[i]) {\n                continue;\n            } else {\n                for (int j = i + 1; j &lt; len; ++j) {\n                    if (t[i] == s[j]) {\n                        for (int k = j - 1; k &gt;= i; --k) {\n                            ans.push_back(k + 1);\n                            swap(s[k], s[k + 1]);\n                        }\n                    }\n                }\n            }\n        }\n        cout &lt;&lt; ans.size() &lt;&lt; \"\\n\";\n        int sz = ans.size();\n        for (int i = 0; i &lt; sz; ++i) {\n            if (i) cout &lt;&lt; \" \";\n            cout &lt;&lt; ans[i];\n        }\n        cout &lt;&lt; \"\\n\";\n    }\n}\n<\/code><\/pre>\n<h2>Problem  C &#8211; Songs Compression<\/h2>\n<h3>\u9898\u610f<\/h3>\n<p>\u624b\u673a\u5bb9\u91cf\u4e3a$$storage$$,\u6bcf\u9996\u6b4c\u7684\u5927\u5c0f\u4e3a$$s_i$$,\u538b\u7f29\u540e\u4e3a$$c_i$$<br \/>\n\u95ee\u6700\u5c11\u538b\u7f29\u51e0\u9996\u6b4c\u53ef\u4ee5\u88c5\u4e0b\u6240\u6709\u6b4c\u66f2\uff0c\u82e5\u65e0\u89e3\u8f93\u51fa-1<\/p>\n<h3>\u9898\u89e3<\/h3>\n<p>\u8d2a\u5fc3\uff0c\u6839\u636e$$s_i &#8211; c_i$$\u964d\u5e8f\u6392\u5e8f\u53d6\u5230\u7b26\u5408\u6761\u4ef6\u5373\u53ef<br \/>\n\u552f\u4e00\u7684\u65e0\u89e3\u6761\u4ef6\u662f$$\\displaystyle\\sum_i t_i > storage$$<\/p>\n<pre><code class=\" line-numbers\">#include &lt;iostream&gt;\n#include &lt;algorithm&gt;\n#include &lt;cstring&gt;\n#include &lt;array&gt;\n#include &lt;vector&gt;\n\nusing namespace std;\nusing ll = long long;\nusing pll = pair&lt;ll, ll&gt;;\nconst int maxn = 1e5 + 6;\narray&lt;pll, maxn&gt; song;\n\nbool cmp(pll a, pll b) {\n    return a.first - a.second &gt; b.first - b.second;\n}\n\nint main() {\n    int tot, storage;\n    cin &gt;&gt; tot &gt;&gt; storage;\n    ll sum1 = 0, sum2 = 0;\n    for (int i = 0; i &lt; tot; ++i) {\n        ll a, b;\n        cin &gt;&gt; a &gt;&gt; b;\n        sum1 += a;\n        sum2 += b;\n        song[i].first = a;\n        song[i].second = b;\n    }\n    if (sum2 &gt; storage) {\n        cout &lt;&lt; -1 &lt;&lt; '\\n';\n    } else {\n        sort(song.begin(), song.begin() + tot, cmp);\n        int ans = 0;\n        for (int i = 0; i &lt; tot &amp;&amp; sum1 &gt; storage; ++i) {\n            sum1 -= song[i].first - song[i].second;\n            ++ans;\n        }\n        cout &lt;&lt; ans &lt;&lt; \"\\n\";\n    }\n}\n<\/code><\/pre>\n<h2>Problem D &#8211; Walking Between Houses<\/h2>\n<h3>\u9898\u610f<\/h3>\n<p>\u6709$$n$$\u5ea7\u623f\u5b50\uff0c\u4f60\u7684\u4f4d\u7f6e\u662f1,\u623f\u5b50\u7684\u533a\u95f4\u4e3a$$[1,n]$$,\u623f\u5b50\u4e4b\u95f4\u8ddd\u79bb\u4e3a$$|i &#8211; j|$$,\u6bcf\u6b21\u8fdb\u884c\u4e00\u6b21\u79fb\u52a8\uff0c\u9700\u6ee1\u8db3$$|i-j|>0$$<br \/>\n\u95ee\u80fd\u5426\u5728$$K$$\u6b21\u79fb\u52a8\u4f7f$$\\displaystyle\\sum move = distance$$<br \/>\n\u65e0\u89e3\u8f93\u51faNO<br \/>\n\u6709\u89e3\u8f93\u51faYES\u548c\u5177\u4f53\u65b9\u6848\uff0c<\/p>\n<h3>\u9898\u89e3<\/h3>\n<p>\u6bd4\u8f83\u6076\u5fc3\u7684\u6a21\u62df<br \/>\n\u65e0\u89e3\u7684\u60c5\u51b5\u662f\u4ece$$1\\to n$$\u8d70$$K$$\u6b21\u90fd\u65e0\u6cd5\u5927\u4e8e\u7b49\u4e8e$$distance$$<br \/>\n\u4ee5\u53ca$$distance &lt; K$$<br \/>\n\u6bcf\u6b21\u6a21\u62df\u79fb\u52a8\uff0c\u79fb\u52a8\u7684\u6b65\u6570\u662f$$jump = distance \/ K$$,\u82e5$$distance \/ K > 0$$\uff0c\u5219$$jump = distance \/ K + 1 $$<br \/>\n\u7136\u540e$$distance -= jump$$,$$K-=1$$<\/p>\n<pre><code class=\" line-numbers\">#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\ntypedef long long ll;\nint main()\n{\n    ll n, k, s;\n    while(~scanf(\"%lld%lld%lld\", &amp;n, &amp;k, &amp;s)){\n        if(k &gt; s || k*(n-1) &lt; s){\n            printf(\"NO\\n\");\n            continue;\n        }\n        printf(\"YES\\n\");\n        ll cur = 1;\n        while(k){\n            ll t = s\/k;\n            if(s%k)\n                t++;\n            s -= t;\n            if(cur &gt; n\/2){\n                cur -= t;\n            }\n            else{\n                cur += t;\n            }\n            printf(\"%lld \", cur);\n            k--;\n        }\n        printf(\"\\n\");\n    }\n    return 0;\n}\n<\/code><\/pre>\n<h2>Problem E1 &#8211; Stars Drawing (Easy Edition)<\/h2>\n<h3>\u9898\u610f<\/h3>\n<p>\u6709\u8fd9\u4e48\u4e00\u4e2a\u661f\u661f\u957f\u8fd9\u4e2a\u6837 \u4ee5\u6b21\u7c7b\u63a8<\/p>\n<pre><code class=\" line-numbers\">..*..\n.***.\n..*..\n<\/code><\/pre>\n<p>\u95ee\u7ed9\u5b9a\u7684\u56fe\u4e2d\u7531\u51e0\u4e2a\u7c7b\u4f3c\u7684\u661f\u661f\u7ec4\u6210\uff0c\u8f93\u51fa\u4efb\u610f\u4e00\u7ec4\u89e3\u5373\u53ef\uff0c\u65e0\u89e3\u8f93\u51fa-1<\/p>\n<h3>\u9898\u89e3<\/h3>\n<p>\u6a21\u62df \u8d2a\u5fc3\u53d6<br \/>\n\u6ce8\u610f\u505a\u597d\u6807\u8bb0\u5c31\u884c<\/p>\n<pre><code class=\" line-numbers\">#include &lt;iostream&gt;\n#include &lt;algorithm&gt;\n#include &lt;vector&gt;\n#include &lt;regex&gt;\n\nusing namespace std;\nusing ll = long long;\nusing pll = pair&lt;ll, ll&gt;;\nusing pii = pair&lt;int, int&gt;;\nconst int maxn = 1e2 + 1e1;\narray&lt;array&lt;int, maxn&gt;, maxn&gt; t;\narray&lt;array&lt;char, maxn&gt;, maxn&gt; s;\n\nint main() {\n    ios_base::sync_with_stdio(0);\n    cin.tie(0);\n    cout.tie(0);\n    int n, m, a, l;\n    for (auto &amp;i:s) {\n        i.fill(0);\n    }\n    for (auto &amp;i:t) {\n        i.fill(0);\n    }\n    vector&lt;pair&lt;pii, int&gt;&gt; v;\n    cin &gt;&gt; n &gt;&gt; m;\n\n    for (int i = 0; i &lt; n; i++) {\n        for (int j = 0; j &lt; m; j++) {\n            cin &gt;&gt; s[i][j];\n            if (s[i][j] == '*') {\n                t[i][j] = 1;\n            }\n        }\n    }\n\n    for (int i = 0; i &lt; n; i++) {\n        for (int j = 0; j &lt; m; j++) {\n            if (s[i][j] == '*') {\n                a = 0;\n\n                for (int x = i - 1; x &gt;= 0; --x) {\n                    if (s[x][j] == '*') { ++a; }\n                    else { break; }\n                }\n                l = a;\n                a = 0;\n                for (int x = i + 1; x &lt; n; ++x) {\n                    if (s[x][j] == '*') { ++a; }\n                    else { break; }\n                }\n                l = min(l, a);\n                a = 0;\n                for (int y = j - 1; y &gt;= 0; --y) {\n                    if (s[i][y] == '*') { ++a; }\n                    else { break; }\n                }\n                l = min(l, a);\n                a = 0;\n                for (int y = j + 1; y &lt; m; ++y) {\n                    if (s[i][y] == '*') { ++a; }\n                    else { break; }\n                }\n                l = min(l, a);\n\n                if (l) {\n                    v.push_back({{i + 1, j + 1}, l});\n                    t[i][j] = 2;\n\n                    for (int x = i - 1, u = l; u; --x, --u) {\n                        t[x][j] = 2;\n                    }\n\n                    for (int x = i + 1, u = l; u; ++x, --u) {\n                        t[x][j] = 2;\n                    }\n\n                    for (int y = j - 1, u = l; u; --u, --y) {\n                        t[i][y] = 2;\n                    }\n\n                    for (int y = j + 1, u = l; u; ++y, --u) {\n                        t[i][y] = 2;\n                    }\n                }\n            }\n        }\n    }\n\n    bool invalid = false;\n\n    for (int i = 0; i &lt; n; ++i) {\n        for (int j = 0; j &lt; m; ++j) {\n            if (t[i][j] == 1) {\n                invalid = true;\n                break;\n            }\n        }\n    }\n\n    if (invalid) {\n        cout &lt;&lt; -1 &lt;&lt; \"\\n\";\n    } else {\n        cout &lt;&lt; v.size() &lt;&lt; \"\\n\";\n        for (auto i:v) {\n            cout &lt;&lt; i.first.first &lt;&lt; \" \" &lt;&lt; i.first.second &lt;&lt; \" \" &lt;&lt; i.second &lt;&lt; \"\\n\";\n        }\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Problem A Points in Segments \u9898\u610f \u7ed9\u4f60\u82e5\u5e72\u4e2a\u533a\u95f4\uff0c\u4ee5\u53ca\u533a\u95f4\u5927\u5c0fn,\u95ee\u4f60\u5728\u533a\u95f4$$ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[39,46,22],"tags":[],"class_list":["post-350","post","type-post","status-publish","format-standard","hentry","category-c","category-codeforces","category-22"],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8UC2c-5E","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/350","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=350"}],"version-history":[{"count":1,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/350\/revisions"}],"predecessor-version":[{"id":351,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/350\/revisions\/351"}],"wp:attachment":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}