{"id":113,"date":"2023-03-31T19:13:00","date_gmt":"2023-03-31T11:13:00","guid":{"rendered":"https:\/\/solost.cn\/?p=113"},"modified":"2023-03-31T20:34:18","modified_gmt":"2023-03-31T12:34:18","slug":"213","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=113","title":{"rendered":"Codeforces Round 861 (Div. 2) &#8211; C. Unlucky Numbers"},"content":{"rendered":"<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/11\/image-16.png\" alt=\"image.png\" title=\"image.png\"><\/p>\n<h2>\u9898\u76ee\u94fe\u63a5<\/h2>\n<p><a href=\"https:\/\/codeforces.com\/contest\/1808\/problem\/C\">\u94fe\u63a5<\/a><\/p>\n<h2>\u9898\u76ee\u5927\u610f<\/h2>\n<p>\u7ed9\u4f60\u4e00\u4e2a\u533a\u95f4<code>L, R<\/code>\u95ee\u4f60\u8fd9\u4e2a\u533a\u95f4\u5185\u6700\u4e0d\u5e78\u8fd0\u7684\u6570\u662f\u591a\u5c11\uff0c\u7b54\u6848\u53ef\u80fd\u6709\u591a\u4e2a\uff0c\u6700\u4e0d\u5e78\u8fd0\u7684\u5b9a\u4e49\u662f\u4e00\u4e2a\u6570\u91cc\u9762\u6700\u5927\u4f4d\u51cf\u53bb\u6700\u5c0f\u4f4d\u5dee\u503c\u6700\u5c0f\u3002<\/p>\n<h2>\u9898\u89e3<\/h2>\n<p>\u8fd9\u4e2a\u9898\u521a\u5f00\u59cb\u60f3\u7740dfs\u641c\u7d22\uff0c\u5206\u4e24\u79cd\u60c5\u51b5\u3002<\/p>\n<ul>\n<li>\u4f4d\u6570\u4e0d\u540c<br \/>\u4f4d\u6570\u4e0d\u540c\u76f4\u63a5\u904d\u5386<\/li>\n<li>\u4f4d\u6570\u76f8\u540c<br \/>\u5982\u679c\u8fd9\u4e00\u4f4d\u76f8\u540c\uff0c\u5c31\u5f80\u4e0b\u627e\uff0c\u5982\u679c\u4e0d\u540c\uff0c\u5206\u4e3a\u4e0a\u8fb9\u754c\u4e0b\u8fb9\u754c\u548c\u4e2d\u95f4<\/li>\n<\/ul>\n<p>\u6700\u540e\u4f18\u5316\u4e86\u4e00\u4e0b\u5982\u679c\u628a\u540e\u9762\u7684\u5168\u90e8\u6539\u6210\u548c\u5f53\u524d\u904d\u5386\u7684\u6570\u5b57\u76f8\u540c\uff0c\u7136\u540e\u518d\u627e\u6700\u5c0f\uff0c\u7531\u4e8e\u641c\u7d22\u7684\u65f6\u5019\u4e0d\u77e5\u9053\u6700\u5c0f\u503c\u662f\u591a\u5c11\uff0c\u53cd\u800c\u5199\u51fa\u6765\u548c\u66b4\u529b\u7684\u6ca1\u5565\u533a\u522b\u3002<\/p>\n<p>\u770b\u4e86\u770b\u522b\u4eba\u7684\u601d\u8def\uff0c\u81ea\u5df1\u91cd\u65b0\u5199\u4e86\u4e00\u4e0b\u3002\u5176\u5b9e\u66f4\u4e0a\u9762\u7684\u601d\u8def\u5dee\u4e0d\u591a\uff0c\u5c31\u662f\u628a\u4ece\u540e\u9762\u67d0\u4e00\u4f4d\u5f00\u59cb\uff0c\u628a\u4ed6\u6362\u6210\u4e00\u5806\u76f8\u540c\u7684\u6570\u3002\u7136\u540e\u5728\u8303\u56f4\u5185\u5c31\u66f4\u65b0\u4e00\u4e0b\u503c\u3002<\/p>\n<pre><code class=\"lang-cpp\">#include&lt;map&gt;\n#include&lt;set&gt;\n#include&lt;stack&gt;\n#include&lt;queue&gt;\n#include&lt;cmath&gt;\n#include&lt;vector&gt;\n#include&lt;bitset&gt;\n#include&lt;cstdio&gt;\n#include&lt;cstring&gt;\n#include&lt;fstream&gt;\n#include&lt;cstdlib&gt;\n#include&lt;iostream&gt;\n#include&lt;algorithm&gt;\n#include&lt;unordered_map&gt;\n#include&lt;unordered_set&gt;\n\nusing namespace std;\n#define x first\n#define y second\n#define endl &#039;\\n&#039;\n#define IOS                       \\\n    ios_base::sync_with_stdio(0); \\\n    cin.tie(0);                   \\\n    cout.tie(0);\ntypedef long long ll;\ntypedef pair&lt;int,int&gt; PII;\ntypedef unsigned long long ull;\nconst int INF = 0x3f3f3f3f, mod = 1000000007;\nconst int N = 2e5 + 10;\nll l, r;\nbool compare(ll x){\n    if(x &lt; l || x &gt; r) return false;\n    return true;\n}\n\nint check(ll x){\n    int minn, maxx;\n    maxx = minn = x % 10;\n    while(x){\n        int t = x % 10;\n        maxx = max(maxx, t);\n        minn = min(minn, t);\n        x \/= 10;\n    }\n    return maxx - minn;\n}\n\nvoid op(ll x, vector&lt;int&gt; &amp;a){\n    while(x){\n        a.push_back(x % 10);\n        x \/= 10;\n    }\n}\n\nvoid solve(){\n    cin &gt;&gt; l &gt;&gt; r;\n    vector&lt;int&gt; a, b;\n    op(l, a), op(r, b);\n    ll ans = 10, var, x = 0;\n    for(int i = a.size() - 1; i &gt;= 0; i--){\/\/\u679a\u4e3e\u4ece\u54ea\u4e00\u4f4d\u5f00\u59cb\u6362\u503c\n        for(int j = 0; j &lt; 10; j++){\/\/\u679a\u4e3e\u6362\u54ea\u4e00\u4e2a\u503c\n            ll res = x;\n            for(int k = i; k &gt;= 0; k--){\n                res = res * 10 + j;\n            }\n            if(!compare(res)) continue;\/\/\u68c0\u67e5\u662f\u4e0d\u662f\u5408\u6cd5\n            int t = check(res);\/\/\u8ba1\u7b97\u5e78\u8fd0\u503c\n            if(t &lt; ans){\n                ans = t;\n                var = res;\n            }\n        }\n        x = x * 10 + a[i];\n    }\n    x = 0;\n    for(int i = b.size() - 1; i &gt;= 0; i--){\n        for(int j = 0; j &lt; 10; j++){\n            ll res = x;\n            for(int k = i; k &gt;= 0; k--){\n                res = res * 10 + j;\n            }\n            if(!compare(res)) continue;\n            int t = check(res);\n            if(t &lt; ans){\n                ans = t;\n                var = res;\n            }\n        }\n        x = x * 10 + b[i];\n    }\n    cout &lt;&lt; var &lt;&lt; endl;\n}\nint main(){\n    \/\/ IOS;\n    int t = 1;\n    cin &gt;&gt; t;\n    while(t--){\n        solve();\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u94fe\u63a5 \u94fe\u63a5 \u9898\u76ee\u5927\u610f \u7ed9\u4f60\u4e00\u4e2a\u533a\u95f4L, R\u95ee\u4f60\u8fd9\u4e2a\u533a\u95f4\u5185\u6700\u4e0d\u5e78\u8fd0\u7684\u6570\u662f\u591a\u5c11\uff0c\u7b54\u6848\u53ef\u80fd\u6709\u591a\u4e2a\uff0c\u6700\u4e0d\u5e78\u8fd0\u7684\u5b9a\u4e49\u662f\u4e00\u4e2a\u6570\u91cc\u9762\u6700\u5927\u4f4d\u51cf\u53bb\u6700\u5c0f\u4f4d\u5dee\u503c\u6700\u5c0f\u3002 \u9898\u89e3 \u8fd9\u4e2a\u9898\u521a\u5f00\u59cb\u60f3\u7740dfs\u641c\u7d22\uff0c\u5206\u4e24\u79cd\u60c5\u51b5\u3002 \u4f4d\u6570\u4e0d\u540c\u4f4d\u6570\u4e0d\u540c\u76f4\u63a5\u904d\u5386 \u4f4d\u6570\u76f8\u540c\u5982\u679c\u8fd9\u4e00\u4f4d\u76f8\u540c\uff0c\u5c31\u5f80\u4e0b\u627e\uff0c\u5982\u679c\u4e0d\u540c\uff0c\u5206\u4e3a\u4e0a\u8fb9\u754c\u4e0b\u8fb9\u754c\u548c\u4e2d\u95f4 \u6700\u540e\u4f18\u5316\u4e86\u4e00\u4e0b\u5982\u679c\u628a\u540e\u9762\u7684\u5168\u90e8\u6539\u6210\u548c\u5f53\u524d\u904d\u5386\u7684\u6570\u5b57\u76f8\u540c\uff0c\u7136\u540e\u518d\u627e\u6700\u5c0f\uff0c\u7531\u4e8e\u641c\u7d22\u7684\u65f6\u5019\u4e0d\u77e5\u9053\u6700\u5c0f\u503c\u662f\u591a\u5c11\uff0c\u53cd\u800c\u5199\u51fa\u6765\u548c\u66b4\u529b\u7684\u6ca1\u5565\u533a\u522b\u3002 \u770b\u4e86\u770b\u522b\u4eba\u7684\u601d\u8def\uff0c\u81ea\u5df1\u91cd\u65b0\u5199\u4e86\u4e00\u4e0b\u3002\u5176\u5b9e\u66f4\u4e0a\u9762\u7684\u601d\u8def\u5dee\u4e0d\u591a\uff0c\u5c31\u662f\u628a\u4ece\u540e\u9762\u67d0\u4e00\u4f4d\u5f00\u59cb\uff0c\u628a\u4ed6\u6362\u6210\u4e00\u5806\u76f8\u540c\u7684\u6570\u3002\u7136\u540e\u5728\u8303\u56f4\u5185\u5c31\u66f4\u65b0\u4e00\u4e0b\u503c\u3002 #include&lt;map&gt; #include&lt;set&gt; #include&lt;stack&gt; #include&lt;queue&gt; #include&lt;cmath&gt; #include&lt;vector&gt; #include&lt;bitset&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;fstream&gt; #include&lt;cstdlib&gt; #include&lt;iostream&gt; #include&lt;algorithm&gt; #include&lt;unordered_map&gt; #include&lt;unordered_set&gt; using namespace std; #define x first #define y second #define endl &#039;\\n&#039; #define IOS \\ ios_base::sync_with_stdio(0); \\ cin.tie(0); \\ cout.tie(0); typedef long long ll; typedef pair&lt;int,int&gt; PII; typedef unsigned [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[46,7],"class_list":["post-113","post","type-post","status-publish","format-standard","hentry","category-solution","tag-46","tag-7"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=113"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/113\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}