{"id":249,"date":"2023-07-07T13:45:00","date_gmt":"2023-07-07T05:45:00","guid":{"rendered":"https:\/\/solost.cn\/?p=249"},"modified":"2023-07-07T13:45:24","modified_gmt":"2023-07-07T05:45:24","slug":"377","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=249","title":{"rendered":"Codeforces Round 878 (Div. 3) &#8211; D. Wooden Toy Festival"},"content":{"rendered":"<h1>\u9898\u76ee\u94fe\u63a5<\/h1>\n<p><a href=\"https:\/\/codeforces.com\/contest\/1840\/problem\/D\">\u94fe\u63a5<\/a><\/p>\n<h2>\u9898\u76ee\u5927\u610f<\/h2>\n<p>\u7ed9\u4e00\u4e2a\u957f\u5ea6\u4e3an\u7684\u6570\u7ec4\uff0c\u95ee\u4f60\u6709\u4e09\u4e2a\u6570\uff0cx,y,z,\u4f7f\u5f97min(ans, max(abs(x - ai), abs(y - ai), abs(z - ai))\u7684\u503c\u662f\u591a\u5c11\uff1f<\/p>\n<h2>\u9898\u89e3<\/h2>\n<p>\u8fd9\u5c31\u76f8\u5f53\u4e8e\u4e00\u4e2a\u6392\u5b8c\u5e8f\u7684\u6570\u7ec4\uff0c\u7136\u540e\u5206\u6210\u4e09\u6bb5\uff0c\u8fd9\u4e09\u6bb5\u5206\u522b\u662f\u6700\u96c6\u4e2d\u7684\uff0c\u7136\u540e\u5206\u522b\u6c42\u7740\u4e09\u6bb5\u7684\u534a\u5f84\u3002\u6700\u66b4\u529b\u7684\u529e\u6cd5\u5c31\u662f\u76f4\u63a5\u5bfb\u627e\u4e24\u4e2a\u4e2d\u65ad\u70b9\uff0c\u4f46\u662f\u8fd9\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u662fO(N * N) ,\u65e0\u6cd5\u901a\u8fc7\uff0c\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\uff0c\u56fa\u5b9a\u7b2c\u4e00\u6bb5\u7684\u7aef\u70b9\uff0c\u5c31\u76f8\u5f53\u4e8e\u628a\u540e\u4e00\u6bb5\u5206\u6210\u4e24\u6bb5\uff0c\u8ba9\u8fd9\u4e24\u6bb5\u7684\u6700\u5927\u503c\u6700\u5c0f\uff0c\u90a3\u4e48\u529e\u6cd5\u5c31\u662f\u4e8c\u5206\uff0c\u968f\u7740\u7aef\u70b9\u5411\u53f3\u79fb\u52a8\uff0c\u5de6\u8fb9\u533a\u95f4\u7684\u8d21\u732e\u503c\u4e0d\u65ad\u589e\u5927\uff0c\u53f3\u8fb9\u7684\u4e0d\u65ad\u51cf\u5c0f\uff0c\u90a3\u4e48\u4ed6\u4fe9\u6700\u76f8\u8fd1\u7684\u65f6\u5019\u5c31\u662f\u8d21\u732e\u503c\u6700\u5c0f\u7684\u65f6\u5019\u3002\u7136\u540e\u7b2c\u4e00\u4e2a\u7aef\u70b9\u7684\u904d\u5386\u65f6\u95f4\u590d\u6742\u5ea6\u662fn\uff0c\u4e8c\u5206\u662flogn\uff0c\u5728\u8fd9\u4e2a\u6570\u91cf\u7ea7\u4e0b\u662f\u53ef\u4ee5\u901a\u8fc7\u7684\u3002\u7136\u540e\u628a\u8fd9\u4e2a\u6570\u7ec4\u5206\u6210\u4e09\u6bb5\uff0c\u95ee\u9898\u5c31\u8f6c\u6362\u6210\u8fd9\u4e09\u6bb5\u7684\u534a\u5f84\u6700\u957f\u7684\u6700\u77ed\u662f\u591a\u5c11\uff1f<\/p>\n<h2>\u4ee3\u7801<\/h2>\n<pre><code class=\"lang-cpp\">#include &lt;algorithm&gt;\n#include &lt;bitset&gt;\n#include &lt;climits&gt;\n#include &lt;cmath&gt;\n#include &lt;cstdio&gt;\n#include &lt;cstdlib&gt;\n#include &lt;cstring&gt;\n#include &lt;fstream&gt;\n#include &lt;iostream&gt;\n#include &lt;iterator&gt;\n#include &lt;map&gt;\n#include &lt;queue&gt;\n#include &lt;set&gt;\n#include &lt;stack&gt;\n#include &lt;unordered_map&gt;\n#include &lt;unordered_set&gt;\n#include &lt;vector&gt;\n\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);\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair&lt;ll, ll&gt; pll;\ntypedef pair&lt;int, int&gt; pii;\ntypedef unsigned long long ull;\n\nconst int INF = 0x3f3f3f3f, mod = 1000000007;\nconst int N = 2e5 + 10;\nint a[N], n;\n\n\nvoid solve()\n{\n    cin &gt;&gt; n;\n    for (int i = 1; i &lt;= n; i++) {\n        cin &gt;&gt; a[i];\n    }\n    if (n &lt;= 3) {\n        cout &lt;&lt; &quot;0\\n&quot;;\n        return;\n    }\n    sort(a + 1, a + n + 1);\n    int ans = INT_MAX;\n    for (int i = 1; i &lt;= n - 2; i++) {\n        if ((a[i] - a[1] + 1) \/ 2 &gt;= ans)\/\/\u5982\u679c\u76ee\u524d\u7684\u7b54\u6848\u6bd4\u73b0\u6709\u7684\u8fd8\u5927\uff0c\u6ca1\u5fc5\u8981\u5f80\u4e0b\u641c\n            continue;\n        int l = i + 1, r = n;\n        while (l &lt; r) {\n            int mid = (l + r) &gt;&gt; 1;\n            ans = min(ans, (max(max(a[i] - a[1], a[mid] - a[i + 1]), a[n] - a[mid + 1]) + 1) \/ 2);\n            if ((a[mid] - a[i + 1] + 1) \/ 2 &lt; (a[n] - a[mid + 1] + 1) \/ 2)\/\/\u8fd9\u4e2a\u4f4d\u7f6e&gt;=\u548c&gt;\u662f\u6ca1\u6709\u5f71\u54cd\u7684\uff0c\u56e0\u4e3a\u6211\u4eec\u90fd\u4f1a\u5411\u4e0a\u53d6\u6574\n                l = mid + 1;\n            else\n                r = mid;\n        }\n    }\n    cout &lt;&lt; ans &lt;&lt; endl;\n}\nint main()\n{\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\u4e00\u4e2a\u957f\u5ea6\u4e3an\u7684\u6570\u7ec4\uff0c\u95ee\u4f60\u6709\u4e09\u4e2a\u6570\uff0cx,y,z,\u4f7f\u5f97min(ans, max(abs(x - ai), abs(y - ai), abs(z - ai))\u7684\u503c\u662f\u591a\u5c11\uff1f \u9898\u89e3 \u8fd9\u5c31\u76f8\u5f53\u4e8e\u4e00\u4e2a\u6392\u5b8c\u5e8f\u7684\u6570\u7ec4\uff0c\u7136\u540e\u5206\u6210\u4e09\u6bb5\uff0c\u8fd9\u4e09\u6bb5\u5206\u522b\u662f\u6700\u96c6\u4e2d\u7684\uff0c\u7136\u540e\u5206\u522b\u6c42\u7740\u4e09\u6bb5\u7684\u534a\u5f84\u3002\u6700\u66b4\u529b\u7684\u529e\u6cd5\u5c31\u662f\u76f4\u63a5\u5bfb\u627e\u4e24\u4e2a\u4e2d\u65ad\u70b9\uff0c\u4f46\u662f\u8fd9\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u662fO(N * N) ,\u65e0\u6cd5\u901a\u8fc7\uff0c\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\uff0c\u56fa\u5b9a\u7b2c\u4e00\u6bb5\u7684\u7aef\u70b9\uff0c\u5c31\u76f8\u5f53\u4e8e\u628a\u540e\u4e00\u6bb5\u5206\u6210\u4e24\u6bb5\uff0c\u8ba9\u8fd9\u4e24\u6bb5\u7684\u6700\u5927\u503c\u6700\u5c0f\uff0c\u90a3\u4e48\u529e\u6cd5\u5c31\u662f\u4e8c\u5206\uff0c\u968f\u7740\u7aef\u70b9\u5411\u53f3\u79fb\u52a8\uff0c\u5de6\u8fb9\u533a\u95f4\u7684\u8d21\u732e\u503c\u4e0d\u65ad\u589e\u5927\uff0c\u53f3\u8fb9\u7684\u4e0d\u65ad\u51cf\u5c0f\uff0c\u90a3\u4e48\u4ed6\u4fe9\u6700\u76f8\u8fd1\u7684\u65f6\u5019\u5c31\u662f\u8d21\u732e\u503c\u6700\u5c0f\u7684\u65f6\u5019\u3002\u7136\u540e\u7b2c\u4e00\u4e2a\u7aef\u70b9\u7684\u904d\u5386\u65f6\u95f4\u590d\u6742\u5ea6\u662fn\uff0c\u4e8c\u5206\u662flogn\uff0c\u5728\u8fd9\u4e2a\u6570\u91cf\u7ea7\u4e0b\u662f\u53ef\u4ee5\u901a\u8fc7\u7684\u3002\u7136\u540e\u628a\u8fd9\u4e2a\u6570\u7ec4\u5206\u6210\u4e09\u6bb5\uff0c\u95ee\u9898\u5c31\u8f6c\u6362\u6210\u8fd9\u4e09\u6bb5\u7684\u534a\u5f84\u6700\u957f\u7684\u6700\u77ed\u662f\u591a\u5c11\uff1f \u4ee3\u7801 #include &lt;algorithm&gt; #include &lt;bitset&gt; #include &lt;climits&gt; #include &lt;cmath&gt; #include &lt;cstdio&gt; #include &lt;cstdlib&gt; #include &lt;cstring&gt; #include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;iterator&gt; #include &lt;map&gt; #include &lt;queue&gt; #include &lt;set&gt; #include &lt;stack&gt; #include &lt;unordered_map&gt; #include &lt;unordered_set&gt; #include &lt;vector&gt; #define x [&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":[39,5],"class_list":["post-249","post","type-post","status-publish","format-standard","hentry","category-solution","tag-39","tag-5"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/249","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=249"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/249\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}