{"id":36110,"date":"2025-05-07T15:52:24","date_gmt":"2025-05-07T07:52:24","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/36110.html"},"modified":"2025-05-07T15:52:24","modified_gmt":"2025-05-07T07:52:24","slug":"%e8%93%9d%e6%a1%a5%e6%9d%af%e5%88%b7%e9%a2%98-%e7%ac%ac%e5%8d%81%e4%ba%94%e5%b1%8a%e8%93%9d%e6%a1%a5%e6%9d%af%e5%a4%a7%e8%b5%9b%e8%bd%af%e4%bb%b6%e8%b5%9b%e7%9c%81%e8%b5%9bc-c","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/36110.html","title":{"rendered":"\u84dd\u6865\u676f\u5237\u9898\u2014\u2014\u7b2c\u5341\u4e94\u5c4a\u84dd\u6865\u676f\u5927\u8d5b\u8f6f\u4ef6\u8d5b\u7701\u8d5bC\/C++ \u5927\u5b66 B \u7ec4"},"content":{"rendered":"<h2 style=\"background-color:transparent\">\u4e00\u30010\u63e1\u624b\u95ee\u9898 &#8211; \u84dd\u6865\u4e91\u8bfe<\/h2>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"854\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075221-681b11354f672.png\" width=\"567\" \/><\/p>\n<h3>\u7b97\u6cd5\u4ee3\u7801&#xff1a;<\/h3>\n<p>#include &lt;iostream&gt;<br \/>\nusing namespace std;<br \/>\nint main()<br \/>\n{<br \/>\n    int sum&#061;0;<br \/>\n    for(int i&#061;49;i&gt;&#061;7;i&#8211;)<br \/>\n        sum&#043;&#061;i;<br \/>\n    cout&lt;&lt;sum&lt;&lt;endl;<br \/>\n    return 0;<br \/>\n} <\/p>\n<p>\u76f4\u63a5\u66b4\u529b&#xff0c;\u9898\u610f\u5f88\u6e05\u6670&#xff0c;\u7d2f\u52a0\u5373\u53ef\u3002\u00a0<\/p>\n<\/p>\n<h2>\u4e8c\u30010\u5c0f\u7403\u53cd\u5f39 &#8211; \u84dd\u6865\u4e91\u8bfe<\/h2>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"755\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075221-681b113566a92.png\" width=\"557\" \/><\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"417\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075221-681b11357c0e3.png\" width=\"477\" \/><\/p>\n<h3>\u7b97\u6cd5\u4ee3\u7801&#xff1a;\u00a0<\/h3>\n<p>#include&lt;iostream&gt;  \/\/ \u5f15\u5165\u8f93\u5165\u8f93\u51fa\u6d41\u5e93&#xff0c;\u7528\u4e8e\u6807\u51c6\u8f93\u5165\u8f93\u51fa\u64cd\u4f5c<br \/>\n#include&lt;iomanip&gt;    \/\/ \u5f15\u5165\u8f93\u5165\u8f93\u51fa\u64cd\u7eb5\u5e93&#xff0c;\u7528\u4e8e\u683c\u5f0f\u5316\u8f93\u51fa&#xff08;\u5982\u8bbe\u7f6e\u5c0f\u6570\u70b9\u7cbe\u5ea6&#xff09;<br \/>\n#include&lt;cmath&gt;      \/\/ \u5f15\u5165\u6570\u5b66\u51fd\u6570\u5e93&#xff0c;\u7528\u4e8e\u6570\u5b66\u8fd0\u7b97&#xff08;\u5982\u5e73\u65b9\u6839&#xff09;<\/p>\n<p>using namespace std; \/\/ \u4f7f\u7528\u6807\u51c6\u547d\u540d\u7a7a\u95f4&#xff0c;\u907f\u514d\u6bcf\u6b21\u8c03\u7528\u6807\u51c6\u5e93\u51fd\u6570\u65f6\u90fd\u8981\u52a0std::<\/p>\n<p>\/\/ \u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570check&#xff0c;\u7528\u4e8e\u68c0\u67e5\u4e24\u4e2a\u6574\u6570a\u548cb\u662f\u5426\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6<br \/>\nbool check(int a, int b) {<br \/>\n    \/\/ \u5982\u679ca\u80fd\u88abb\u6574\u9664&#xff0c;\u5e76\u4e14a\u9664\u4ee5b\u7684\u7ed3\u679c\u662f\u5076\u6570&#xff0c;\u5219\u8fd4\u56detrue<br \/>\n    if (a % b &#061;&#061; 0 &amp;&amp; (a \/ b) % 2 &#061;&#061; 0) return true;<br \/>\n    return false;  \/\/ \u5426\u5219\u8fd4\u56defalse<br \/>\n}<\/p>\n<p>\/\/ \u4e3b\u51fd\u6570<br \/>\nint main() {<br \/>\n    long long x &#061; 343720, y &#061; 233333;  \/\/ \u5b9a\u4e49\u4e24\u4e2a\u957f\u6574\u578b\u53d8\u91cfx\u548cy&#xff0c;\u5e76\u8d4b\u4e88\u521d\u59cb\u503c<br \/>\n    long long t &#061; 1;  \/\/ \u5b9a\u4e49\u957f\u6574\u578b\u53d8\u91cft&#xff0c;\u5e76\u521d\u59cb\u5316\u4e3a1<br \/>\n    long long lx, ly;  \/\/ \u5b9a\u4e49\u4e24\u4e2a\u957f\u6574\u578b\u53d8\u91cflx\u548cly&#xff0c;\u7528\u4e8e\u5b58\u50a8\u8ba1\u7b97\u8fc7\u7a0b\u4e2d\u7684\u4e34\u65f6\u503c<\/p>\n<p>    \/\/ \u8fdb\u5165\u4e00\u4e2a\u65e0\u9650\u5faa\u73af&#xff0c;\u76f4\u5230\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u65f6\u8df3\u51fa\u5faa\u73af<br \/>\n    while (1) {<br \/>\n        lx &#061; 15 * t;  \/\/ \u8ba1\u7b97lx\u4e3a15\u4e58\u4ee5t<br \/>\n        ly &#061; 17 * t;  \/\/ \u8ba1\u7b97ly\u4e3a17\u4e58\u4ee5t<\/p>\n<p>        \/\/ \u5982\u679clx\u548cx\u6ee1\u8db3check\u51fd\u6570\u7684\u6761\u4ef6&#xff0c;\u4e14ly\u548cy\u4e5f\u6ee1\u8db3check\u51fd\u6570\u7684\u6761\u4ef6&#xff0c;\u5219\u8df3\u51fa\u5faa\u73af<br \/>\n        if (check(lx, x) &amp;&amp; check(ly, y)) break;<\/p>\n<p>        t&#043;&#043;;  \/\/ \u5426\u5219&#xff0c;t\u81ea\u589e1&#xff0c;\u7ee7\u7eed\u5faa\u73af<br \/>\n    }<\/p>\n<p>    \/\/ \u8f93\u51falx\u548cly\u7684\u5e73\u65b9\u548c\u7684\u5e73\u65b9\u6839&#xff0c;\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570<br \/>\n    cout &lt;&lt; setprecision(2) &lt;&lt; fixed &lt;&lt; sqrt(lx * lx &#043; ly * ly);<\/p>\n<p>    return 0;  \/\/ \u7a0b\u5e8f\u6b63\u5e38\u7ed3\u675f&#xff0c;\u8fd4\u56de0<br \/>\n} <\/p>\n<h3>\u95ee\u9898\u80cc\u666f<\/h3>\n<li>\n<h4>\u5c0f\u7403\u8fd0\u52a8&#xff1a;<\/h4>\n<ul>\n<li>\n<p>\u5c0f\u7403\u5728\u957f\u65b9\u5f62\u5185\u4ee5\u56fa\u5b9a\u7684\u901f\u5ea6\u6bd4\u00a0dx:dy&#061;15:17\u8fd0\u52a8\u3002<\/p>\n<\/li>\n<li>\n<p>\u5f53\u5c0f\u7403\u78b0\u5230\u957f\u65b9\u5f62\u7684\u8fb9\u6846\u65f6&#xff0c;\u4f1a\u53d1\u751f\u53cd\u5f39&#xff08;\u5165\u5c04\u89d2\u7b49\u4e8e\u53cd\u5c04\u89d2&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u6211\u4eec\u9700\u8981\u8ba1\u7b97\u5c0f\u7403\u7b2c\u4e00\u6b21\u56de\u5230\u8d77\u70b9\u65f6\u6240\u7ecf\u8fc7\u7684\u603b\u8def\u5f84\u957f\u5ea6\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<h4>\u53cd\u5f39\u7684\u7b49\u6548\u8def\u5f84&#xff1a;<\/h4>\n<ul>\n<li>\n<p>\u53cd\u5f39\u95ee\u9898\u53ef\u4ee5\u901a\u8fc7\u201c\u955c\u50cf\u53cd\u5c04\u6cd5\u201d\u7b80\u5316\u3002\u5c06\u957f\u65b9\u5f62\u65e0\u9650\u590d\u5236&#xff0c;\u5f62\u6210\u4e00\u4e2a\u7f51\u683c&#xff0c;\u5c0f\u7403\u7684\u8def\u5f84\u53ef\u4ee5\u770b\u4f5c\u4e00\u6761\u76f4\u7ebf\u7a7f\u8fc7\u8fd9\u4e9b\u955c\u50cf\u957f\u65b9\u5f62\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c0f\u7403\u7b2c\u4e00\u6b21\u56de\u5230\u8d77\u70b9&#xff0c;\u7b49\u4ef7\u4e8e\u8fd9\u6761\u76f4\u7ebf\u7b2c\u4e00\u6b21\u7a7f\u8fc7\u4e00\u4e2a\u955c\u50cf\u957f\u65b9\u5f62\u7684\u5de6\u4e0a\u89d2\u9876\u70b9\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<h3>\u6570\u5b66\u5206\u6790<\/h3>\n<li>\n<h4>\u8def\u5f84\u6761\u4ef6&#xff1a;<\/h4>\n<ul>\n<li>\n<p>\u5c0f\u7403\u5728\u6c34\u5e73\u65b9\u5411&#xff08;\u957f&#xff09;\u79fb\u52a8\u7684\u603b\u8ddd\u79bb\u5fc5\u987b\u662f\u957f\u65b9\u5f62\u957f\u5ea6\u00a0x&#061;343720\u00a0\u7684\u5076\u6570\u500d\u3002\u8fd9\u662f\u56e0\u4e3a\u6bcf\u6b21\u53cd\u5f39\u90fd\u4f1a\u6539\u53d8\u65b9\u5411&#xff0c;\u53ea\u6709\u5076\u6570\u500d\u624d\u80fd\u8ba9\u5c0f\u7403\u56de\u5230\u8d77\u70b9\u7684\u6c34\u5e73\u4f4d\u7f6e\u3002<\/p>\n<\/li>\n<li>\n<p>\u540c\u7406&#xff0c;\u5c0f\u7403\u5728\u5782\u76f4\u65b9\u5411&#xff08;\u5bbd&#xff09;\u79fb\u52a8\u7684\u603b\u8ddd\u79bb\u5fc5\u987b\u662f\u957f\u65b9\u5f62\u5bbd\u5ea6\u00a0y&#061;233333 \u7684\u5076\u6570\u500d\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<h4>\u516c\u5f0f\u63a8\u5bfc&#xff1a;<\/h4>\n<ul>\n<li>\n<p>\u5c0f\u7403\u5728\u6c34\u5e73\u65b9\u5411\u7684\u79fb\u52a8\u8ddd\u79bb\u4e3a\u00a0lx&#061;15t\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c0f\u7403\u5728\u5782\u76f4\u65b9\u5411\u7684\u79fb\u52a8\u8ddd\u79bb\u4e3a\u00a0ly&#061;17t\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e3a\u4e86\u6ee1\u8db3\u56de\u5230\u8d77\u70b9\u7684\u6761\u4ef6&#xff0c;\u5fc5\u987b\u540c\u65f6\u6ee1\u8db3&#xff1a;<\/p>\n<p> lx&#061;15t&#061;2k\u22c5x&#xff08;\u6c34\u5e73\u65b9\u5411&#xff09;ly&#061;17t&#061;2m\u22c5y&#xff08;\u5782\u76f4\u65b9\u5411&#xff09; <\/p>\n<p>\u5176\u4e2d\u00a0k\u00a0\u548c\u00a0m\u00a0\u662f\u6b63\u6574\u6570\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<h4>\u7b80\u5316\u6761\u4ef6&#xff1a;<\/h4>\n<ul>\n<li>\n<p>\u6211\u4eec\u9700\u8981\u627e\u5230\u6700\u5c0f\u7684\u00a0t&#xff0c;\u4f7f\u5f97\u00a015t \u662f\u00a0x\u00a0\u7684\u5076\u6570\u500d&#xff0c;\u4e14\u00a017t\u662f\u00a0y\u7684\u5076\u6570\u500d\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fd9\u7b49\u4ef7\u4e8e&#xff1a;<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"105\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075221-681b11358c6ea.png\" width=\"484\" \/><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"146\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075221-681b113596766.png\" width=\"861\" \/><\/p>\n<p>setprecision(2)\u00a0\u662f C&#043;&#043; \u6807\u51c6\u5e93\u00a0&lt;iomanip&gt;\u00a0\u4e2d\u7684\u4e00\u4e2a\u64cd\u7eb5\u7b26&#xff0c;\u7528\u4e8e\u8bbe\u7f6e\u6d6e\u70b9\u6570\u8f93\u51fa\u7684\u7cbe\u5ea6\u3002\u5177\u4f53\u6765\u8bf4&#xff0c;\u5b83\u63a7\u5236\u8f93\u51fa\u6d41\u4e2d\u6d6e\u70b9\u6570\u7684\u5c0f\u6570\u70b9\u540e\u7684\u4f4d\u6570\u3002<\/p>\n<h3>\u8be6\u7ec6\u89e3\u91ca<\/h3>\n<ul>\n<li>\n<p>setprecision(n)&#xff1a;\u8bbe\u7f6e\u6d6e\u70b9\u6570\u8f93\u51fa\u7684\u5c0f\u6570\u70b9\u540e\u7684\u4f4d\u6570\u4e3a\u00a0n\u3002\u4f8b\u5982&#xff0c;setprecision(2)\u00a0\u8868\u793a\u8f93\u51fa\u6d6e\u70b9\u6570\u65f6\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>fixed&#xff1a;\u4e0e\u00a0setprecision\u00a0\u7ed3\u5408\u4f7f\u7528&#xff0c;\u8868\u793a\u4f7f\u7528\u56fa\u5b9a\u5c0f\u6570\u683c\u5f0f\u8f93\u51fa\u3002\u8fd9\u610f\u5473\u7740\u5c0f\u6570\u70b9\u540e\u7684\u4f4d\u6570\u662f\u56fa\u5b9a\u7684&#xff0c;\u800c\u4e0d\u662f\u79d1\u5b66\u8ba1\u6570\u6cd5\u3002<\/p>\n<\/li>\n<\/ul>\n<h2 style=\"background-color:transparent\">\u4e09\u30010\u597d\u6570 &#8211; \u84dd\u6865\u4e91\u8bfe\u00a0<\/h2>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"870\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075221-681b1135a7545.png\" width=\"554\" \/><\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"681\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075221-681b1135bb216.png\" width=\"554\" \/><\/p>\n<h3>\u7b97\u6cd5\u4ee3\u7801&#xff1a;<\/h3>\n<p>#include &lt;stdio.h&gt;<br \/>\nint main()<br \/>\n{<br \/>\n    int n, i;<br \/>\n    scanf(&#034;%d&#034;, &amp;n);  \/\/ \u8f93\u5165\u4e00\u4e2a\u6574\u6570 n<br \/>\n    for (; n &gt; 0; n&#8211;)  \/\/ \u4ece n \u5f00\u59cb&#xff0c;\u9012\u51cf\u5230 1<br \/>\n    {<br \/>\n        for (int m &#061; n; m &gt; 0;)  \/\/ \u5bf9\u6bcf\u4e2a\u6570\u5b57 m &#061; n&#xff0c;\u68c0\u67e5\u5176\u6bcf\u4e00\u4f4d<br \/>\n        {<br \/>\n            if (m % 2 !&#061; 0) m \/&#061; 10;  \/\/ \u5982\u679c\u6700\u4f4e\u4f4d\u662f\u5947\u6570&#xff0c;\u53bb\u6389\u6700\u4f4e\u4f4d<br \/>\n            else break;  \/\/ \u5982\u679c\u6700\u4f4e\u4f4d\u662f\u5076\u6570&#xff0c;\u9000\u51fa\u5faa\u73af<br \/>\n            if (m % 2 &#061;&#061; 0) m \/&#061; 10;  \/\/ \u5982\u679c\u65b0\u7684\u6700\u4f4e\u4f4d\u662f\u5076\u6570&#xff0c;\u53bb\u6389\u6700\u4f4e\u4f4d<br \/>\n            else break;  \/\/ \u5982\u679c\u65b0\u7684\u6700\u4f4e\u4f4d\u662f\u5947\u6570&#xff0c;\u9000\u51fa\u5faa\u73af<br \/>\n            if (m &#061;&#061; 0) i&#043;&#043;;  \/\/ \u5982\u679c m \u53d8\u4e3a 0&#xff0c;\u8bf4\u660e\u6ee1\u8db3\u6761\u4ef6&#xff0c;\u8ba1\u6570\u5668 i \u589e\u52a0<br \/>\n        }<br \/>\n    }<br \/>\n    printf(&#034;%d&#034;, i);  \/\/ \u8f93\u51fa\u6ee1\u8db3\u6761\u4ef6\u7684\u6570\u5b57\u7684\u6570\u91cf<br \/>\n    return 0;<br \/>\n} <\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u9898\u610f\u6e05\u6670&#xff0c;\u76f4\u63a5\u4e00\u4e2a\u4e00\u4e2a\u6570\u5730\u5faa\u73af\u9012\u51cf&#xff0c;\u7136\u540e\u6309\u89c4\u5219&#xff0c;\u76f4\u63a5\u5224\u65ad\u5947\u6570\u4f4d\u548c\u5076\u6570\u4f4d\u662f\u4e0d\u662f\u7b26\u5408\u6761\u4ef6\u3002<\/p>\n<\/p>\n<h2>\u56db\u30010R \u683c\u5f0f &#8211; \u84dd\u6865\u4e91\u8bfe<\/h2>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"806\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075221-681b1135ceb21.png\" width=\"570\" \/><\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"619\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075221-681b1135e2a57.png\" width=\"557\" \/><\/p>\n<h3>\u81ea\u5df1\u5199\u7684&#xff1a;\u7b97\u6cd5\u4ee3\u7801&#xff08;\u53ea\u80fd\u901a\u8fc750%\u7684\u6d4b\u8bd5\u7528\u4f8b&#xff09;\u00a0<\/h3>\n<p>#include &lt;bits\/stdc&#043;&#043;.h&gt;<br \/>\nusing namespace std;<br \/>\ntypedef long long ll;<\/p>\n<p>\/\/ \u5feb\u901f\u5e42\u51fd\u6570&#xff0c;\u8ba1\u7b97 2^n<br \/>\nll fastPow(int n) {<br \/>\n    ll a &#061; 2;  \/\/ \u5e95\u6570\u4e3a 2<br \/>\n    ll sum &#061; 1;  \/\/ \u521d\u59cb\u5316 sum \u4e3a 1<br \/>\n    while (n) {<br \/>\n        if (n &amp; 1) {<br \/>\n            sum &#061; sum * a;  \/\/ \u5982\u679c\u5f53\u524d\u4f4d\u4e3a 1&#xff0c;\u7d2f\u4e58\u5230 sum<br \/>\n        }<br \/>\n        a &#061; a * a;  \/\/ \u5e95\u6570\u5e73\u65b9<br \/>\n        n &gt;&gt;&#061; 1;  \/\/ \u53f3\u79fb\u4e00\u4f4d<br \/>\n    }<br \/>\n    return sum;<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    int n;<br \/>\n    double d;<br \/>\n    cin &gt;&gt; n &gt;&gt; d;  \/\/ \u8f93\u5165 n \u548c d<br \/>\n    ll ans &#061; fastPow(n);  \/\/ \u8ba1\u7b97 2^n<br \/>\n    ll end_format &#061; round(d * ans);  \/\/ \u5c06 d \u4e58\u4ee5 2^n \u5e76\u56db\u820d\u4e94\u5165<br \/>\n    \/\/round \u51fd\u6570\u7528\u4e8e\u5bf9\u6d6e\u70b9\u6570\u8fdb\u884c\u56db\u820d\u4e94\u5165\u64cd\u4f5c<br \/>\n    printf(&#034;%lld\\\\n&#034;, end_format);  \/\/ \u8f93\u51fa\u7ed3\u679c<br \/>\n    return 0;<br \/>\n} <\/p>\n<h3>\u00a0\u7f57\u52c7\u519b\u8001\u5e08\u7684\u51e0\u884c\u4ee3\u7801&#xff08;50%&#xff09;&#xff08;\u9ad8\u4e0b\u7acb\u5224\u4e86\u5c5e\u4e8e\u662f\u54c8\u54c8&#xff09;\u7b97\u6cd5\u4ee3\u7801&#xff1a;<\/h3>\n<p>#include\u00a0&lt;bits\/stdc&#043;&#043;.h&gt;<br \/>\nusing\u00a0namespace\u00a0std;<br \/>\nint\u00a0main()<br \/>\n{\u00a0 \u00a0\u00a0<br \/>\n    long\u00a0long\u00a0n;\u00a0 \u00a0\u00a0<br \/>\n    double\u00a0s;\u00a0 \u00a0<br \/>\n    cin&gt;&gt;n&gt;&gt;s;\u00a0 \u00a0\u00a0<br \/>\n    long\u00a0long\u00a0 a &#061;\u00a01&lt;&lt;n;\u00a0 \u00a0\u00a0<br \/>\n    long\u00a0long\u00a0b&#061; (long\u00a0long)(a*s*1.0&#043;0.5);\/\/\u52a00.5\u56db\u820d\u4e94\u5165\u00a0 \u00a0<br \/>\n    cout &lt;&lt; b;<br \/>\n} <\/p>\n<h3 style=\"background-color:transparent\">\u9898\u89e3&#xff1a;<\/h3>\n<p>#include&lt;bits\/stdc&#043;&#043;.h&gt;  \/\/ \u5305\u542b\u6240\u6709\u6807\u51c6\u5e93\u5934\u6587\u4ef6<br \/>\nusing namespace std;     \/\/ \u4f7f\u7528\u6807\u51c6\u547d\u540d\u7a7a\u95f4<\/p>\n<p>int main()<br \/>\n{<br \/>\n  int n;<br \/>\n  string d;    \/\/ \u7531\u4e8e\u6570\u5b57\u53ef\u80fd\u975e\u5e38\u5927&#xff0c;\u4f7f\u7528\u5b57\u7b26\u4e32\u6765\u8bfb\u53d6<br \/>\n  cin &gt;&gt; n &gt;&gt; d;  \/\/ \u8f93\u5165\u8f6c\u6362\u53c2\u6570 n \u548c\u6d6e\u70b9\u6570 d<\/p>\n<p>  vector&lt;int&gt; b;  \/\/ \u4f7f\u7528 vector \u6765\u5b58\u50a8\u6570\u5b57\u7684\u6bcf\u4e00\u4f4d&#xff0c;\u65b9\u4fbf\u5904\u7406\u8fdb\u4f4d<br \/>\n  int sum &#061; 0, k &#061; 0;  \/\/ sum \u7528\u4e8e\u8bb0\u5f55\u603b\u4f4d\u6570&#xff0c;k \u7528\u4e8e\u8bb0\u5f55\u5c0f\u6570\u70b9\u7684\u4f4d\u7f6e<\/p>\n<p>  \/\/ \u4ece\u5b57\u7b26\u4e32\u672b\u5c3e\u5f00\u59cb\u904d\u5386&#xff0c;\u5c06\u5b57\u7b26\u8f6c\u6362\u4e3a\u6574\u6570\u5e76\u5b58\u50a8\u5230 vector \u4e2d<br \/>\n  for(int i &#061; d.size() &#8211; 1; i &gt;&#061; 0; i&#8211;)<br \/>\n  {<br \/>\n      if(d[i] !&#061; &#039;.&#039;)<br \/>\n          b.push_back(d[i] &#8211; &#039;0&#039;);  \/\/ \u5c06\u5b57\u7b26\u8f6c\u6362\u4e3a\u6574\u6570\u5e76\u5b58\u50a8<br \/>\n      else {<br \/>\n          k &#061; sum;  \/\/ \u8bb0\u5f55\u5c0f\u6570\u70b9\u7684\u4f4d\u7f6e<br \/>\n      }<br \/>\n      sum&#043;&#043;;  \/\/ \u8bb0\u5f55\u603b\u4f4d\u6570<br \/>\n  }<\/p>\n<p>  int u &#061; b.size();  \/\/ \u8bb0\u5f55\u5f53\u524d\u6570\u5b57\u7684\u4f4d\u6570<\/p>\n<p>  \/\/ \u8fdb\u884c n \u6b21\u4e58\u4ee5 2 \u7684\u64cd\u4f5c<br \/>\n  while(n&#8211;)<br \/>\n  {<br \/>\n    int t &#061; 0;  \/\/ t \u7528\u4e8e\u8bb0\u5f55\u8fdb\u4f4d<br \/>\n    for(int i &#061; 0; i &lt; b.size(); i&#043;&#043;)<br \/>\n    {<br \/>\n        b[i] &#061; b[i] * 2 &#043; t;  \/\/ \u5f53\u524d\u4f4d\u4e58\u4ee5 2 \u5e76\u52a0\u4e0a\u8fdb\u4f4d<br \/>\n        if(b[i] &gt;&#061; 10)<br \/>\n        {<br \/>\n            t &#061; b[i] \/ 10;  \/\/ \u8ba1\u7b97\u65b0\u7684\u8fdb\u4f4d<br \/>\n            b[i] &#061; b[i] % 10;  \/\/ \u53d6\u4f59\u6570\u4f5c\u4e3a\u5f53\u524d\u4f4d\u7684\u503c<br \/>\n        }<br \/>\n        else {<br \/>\n            t &#061; 0;  \/\/ \u5982\u679c\u6ca1\u6709\u8fdb\u4f4d&#xff0c;\u7f6e\u4e3a 0<br \/>\n        }<br \/>\n    }<br \/>\n    if(t)  \/\/ \u5982\u679c\u6700\u540e\u8fd8\u6709\u8fdb\u4f4d&#xff0c;\u6dfb\u52a0\u5230 vector \u4e2d<br \/>\n        b.push_back(t);<br \/>\n  }<\/p>\n<p>  u &#061; b.size();  \/\/ \u66f4\u65b0\u6570\u5b57\u7684\u4f4d\u6570<\/p>\n<p>  int t &#061; 1;  \/\/ \u7528\u4e8e\u5904\u7406\u56db\u820d\u4e94\u5165\u7684\u8fdb\u4f4d<br \/>\n  if(k &amp;&amp; b[k &#8211; 1] &gt;&#061; 5)  \/\/ \u5982\u679c\u9700\u8981\u56db\u820d\u4e94\u5165<br \/>\n  {<br \/>\n    for(int i &#061; k; i &lt; u; i&#043;&#043;)<br \/>\n    {<br \/>\n        b[i] &#061; b[i] &#043; 1;  \/\/ \u5f53\u524d\u4f4d\u52a0 1<br \/>\n        if(b[i] &lt;&#061; 9) {  \/\/ \u5982\u679c\u4e0d\u9700\u8981\u7ee7\u7eed\u8fdb\u4f4d<br \/>\n            t &#061; 0;<br \/>\n            break;<br \/>\n        }<br \/>\n        else {<br \/>\n            b[i] -&#061; 10;  \/\/ \u5982\u679c\u9700\u8981\u7ee7\u7eed\u8fdb\u4f4d<br \/>\n        }<br \/>\n    }<br \/>\n    if(t)  \/\/ \u5982\u679c\u6700\u540e\u8fd8\u6709\u8fdb\u4f4d&#xff0c;\u6dfb\u52a0\u5230 vector \u4e2d<br \/>\n        b.push_back(t);<br \/>\n  }<\/p>\n<p>  \/\/ \u4ece\u6700\u9ad8\u4f4d\u5f00\u59cb\u8f93\u51fa\u7ed3\u679c&#xff0c;\u5ffd\u7565\u5c0f\u6570\u90e8\u5206<br \/>\n  for(int i &#061; b.size() &#8211; 1; i &gt;&#061; k; i&#8211;)<br \/>\n      cout &lt;&lt; b[i];<\/p>\n<p>  return 0;  \/\/ \u7a0b\u5e8f\u7ed3\u675f<br \/>\n} <\/p>\n<h4>1. \u8f93\u5165\u5904\u7406<\/h4>\n<ul>\n<li>\n<p>\u8f93\u5165&#xff1a;\u8bfb\u53d6\u6574\u6570\u00a0n\u00a0\u548c\u6d6e\u70b9\u6570\u00a0d\u3002<\/p>\n<ul>\n<li>\n<p>n\u00a0\u662f\u8f6c\u6362\u53c2\u6570&#xff0c;\u8868\u793a\u9700\u8981\u5c06\u6d6e\u70b9\u6570\u4e58\u4ee5\u00a02^n\u3002<\/p>\n<\/li>\n<li>\n<p>d\u00a0\u662f\u5f85\u8f6c\u6362\u7684\u6d6e\u70b9\u6570&#xff0c;\u53ef\u80fd\u975e\u5e38\u5927&#xff0c;\u56e0\u6b64\u7528\u5b57\u7b26\u4e32\u5b58\u50a8\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u76ee\u6807&#xff1a;\u5c06\u6d6e\u70b9\u6570\u00a0d\u00a0\u8f6c\u6362\u4e3a\u6574\u6570\u5f62\u5f0f&#xff0c;\u65b9\u4fbf\u540e\u7eed\u8ba1\u7b97\u3002<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>2. \u5c06\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u6574\u6570\u5f62\u5f0f<\/h4>\n<ul>\n<li>\n<p>\u904d\u5386\u6d6e\u70b9\u6570\u5b57\u7b26\u4e32&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4ece\u5b57\u7b26\u4e32\u672b\u5c3e\u5f00\u59cb\u904d\u5386&#xff0c;\u5c06\u6bcf\u4e2a\u6570\u5b57\u5b57\u7b26\u8f6c\u6362\u4e3a\u6574\u6570&#xff0c;\u5e76\u5b58\u50a8\u5230\u00a0vector&lt;int&gt; b\u00a0\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u9047\u5230\u5c0f\u6570\u70b9\u00a0.&#xff0c;\u8bb0\u5f55\u5c0f\u6570\u70b9\u7684\u4f4d\u7f6e\u00a0k&#xff0c;\u8868\u793a\u5c0f\u6570\u70b9\u540e\u6709\u00a0k\u00a0\u4f4d\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7ed3\u679c&#xff1a;<\/p>\n<ul>\n<li>\n<p>b\u00a0\u4e2d\u5b58\u50a8\u7684\u662f\u6d6e\u70b9\u6570\u00a0d\u00a0\u7684\u6574\u6570\u5f62\u5f0f&#xff08;\u53bb\u6389\u5c0f\u6570\u70b9&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>k\u00a0\u8bb0\u5f55\u4e86\u5c0f\u6570\u70b9\u7684\u4f4d\u7f6e&#xff0c;\u7528\u4e8e\u540e\u7eed\u56db\u820d\u4e94\u5165\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>3. \u9ad8\u7cbe\u5ea6\u4e58\u4ee5\u00a02^n<\/h4>\n<ul>\n<li>\n<p>\u5faa\u73af\u4e58\u4ee5 2&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8fdb\u884c\u00a0n\u00a0\u6b21\u4e58\u4ee5 2 \u7684\u64cd\u4f5c&#xff0c;\u6bcf\u6b21\u64cd\u4f5c\u90fd\u6a21\u62df\u9ad8\u7cbe\u5ea6\u4e58\u6cd5\u3002<\/p>\n<\/li>\n<li>\n<p>\u6bcf\u6b21\u4e58\u4ee5 2 \u65f6&#xff0c;\u904d\u5386\u00a0b\u00a0\u4e2d\u7684\u6bcf\u4e00\u4f4d&#xff0c;\u8ba1\u7b97\u5f53\u524d\u4f4d\u4e58\u4ee5 2 \u5e76\u52a0\u4e0a\u8fdb\u4f4d\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u5f53\u524d\u4f4d\u7684\u7ed3\u679c\u5927\u4e8e\u7b49\u4e8e 10&#xff0c;\u5219\u8ba1\u7b97\u8fdb\u4f4d&#xff0c;\u5e76\u5c06\u5f53\u524d\u4f4d\u7684\u7ed3\u679c\u53d6\u4f59\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u6700\u540e\u8fd8\u6709\u8fdb\u4f4d&#xff0c;\u5c06\u5176\u6dfb\u52a0\u5230\u00a0b\u00a0\u7684\u672b\u5c3e\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7ed3\u679c&#xff1a;<\/p>\n<ul>\n<li>\n<p>b\u00a0\u4e2d\u5b58\u50a8\u7684\u662f\u6d6e\u70b9\u6570\u00a0d\u00a0\u4e58\u4ee5\u00a02^n\u7684\u7ed3\u679c&#xff0c;\u4ecd\u7136\u662f\u4e00\u4e2a\u9ad8\u7cbe\u5ea6\u6574\u6570\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>4. \u56db\u820d\u4e94\u5165<\/h4>\n<ul>\n<li>\n<p>\u5224\u65ad\u662f\u5426\u9700\u8981\u56db\u820d\u4e94\u5165&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6839\u636e\u5c0f\u6570\u70b9\u7684\u4f4d\u7f6e\u00a0k&#xff0c;\u68c0\u67e5\u5c0f\u6570\u70b9\u540e\u7684\u7b2c\u4e00\u4f4d&#xff08;\u5373\u00a0b[k-1]&#xff09;\u662f\u5426\u5927\u4e8e\u7b49\u4e8e 5\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u5927\u4e8e\u7b49\u4e8e 5&#xff0c;\u5219\u9700\u8981\u8fdb\u884c\u56db\u820d\u4e94\u5165\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u56db\u820d\u4e94\u5165\u64cd\u4f5c&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4ece\u5c0f\u6570\u70b9\u4f4d\u7f6e\u5f00\u59cb&#xff0c;\u5411\u9ad8\u4f4d\u9010\u4f4d\u52a0 1&#xff0c;\u76f4\u5230\u6ca1\u6709\u8fdb\u4f4d\u4e3a\u6b62\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u6700\u9ad8\u4f4d\u4ecd\u6709\u8fdb\u4f4d&#xff0c;\u5c06\u5176\u6dfb\u52a0\u5230\u00a0b\u00a0\u7684\u672b\u5c3e\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7ed3\u679c&#xff1a;<\/p>\n<ul>\n<li>\n<p>b\u00a0\u4e2d\u5b58\u50a8\u7684\u662f\u56db\u820d\u4e94\u5165\u540e\u7684\u6700\u7ec8\u7ed3\u679c\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>5. \u8f93\u51fa\u7ed3\u679c<\/h4>\n<ul>\n<li>\n<p>\u4ece\u6700\u9ad8\u4f4d\u5f00\u59cb\u8f93\u51fa&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4ece\u00a0b\u00a0\u7684\u6700\u9ad8\u4f4d\u5f00\u59cb&#xff0c;\u8f93\u51fa\u6bcf\u4e00\u4f4d\u6570\u5b57\u3002<\/p>\n<\/li>\n<li>\n<p>\u5ffd\u7565\u5c0f\u6570\u90e8\u5206&#xff08;\u5373\u5c0f\u6570\u70b9\u540e\u7684\u4f4d\u6570&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7ed3\u679c&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8f93\u51fa\u7684\u662f\u6d6e\u70b9\u6570\u00a0d\u00a0\u4e58\u4ee5\u00a02^n\u00a0\u5e76\u56db\u820d\u4e94\u5165\u540e\u7684\u6574\u6570\u7ed3\u679c\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>6. \u4ee3\u7801\u7684\u6838\u5fc3\u601d\u60f3<\/h4>\n<ul>\n<li>\n<p>\u9ad8\u7cbe\u5ea6\u8ba1\u7b97&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u7531\u4e8e\u6d6e\u70b9\u6570\u548c\u00a02^n\u00a0\u53ef\u80fd\u975e\u5e38\u5927&#xff0c;\u666e\u901a\u6570\u636e\u7c7b\u578b\u65e0\u6cd5\u5b58\u50a8&#xff0c;\u56e0\u6b64\u4f7f\u7528\u5b57\u7b26\u4e32\u548c\u00a0vector&lt;int&gt;\u00a0\u6765\u6a21\u62df\u9ad8\u7cbe\u5ea6\u8ba1\u7b97\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9010\u4f4d\u5904\u7406&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u901a\u8fc7\u9010\u4f4d\u904d\u5386\u548c\u8fdb\u4f4d\u5904\u7406&#xff0c;\u5b9e\u73b0\u4e86\u9ad8\u7cbe\u5ea6\u4e58\u6cd5\u548c\u56db\u820d\u4e94\u5165\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u56db\u820d\u4e94\u5165&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6839\u636e\u5c0f\u6570\u70b9\u540e\u7684\u7b2c\u4e00\u4f4d\u51b3\u5b9a\u662f\u5426\u9700\u8981\u8fdb\u4f4d&#xff0c;\u6a21\u62df\u4e86\u56db\u820d\u4e94\u5165\u7684\u8fc7\u7a0b\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2 style=\"background-color:transparent\">\u4e94\u3001\u00a00\u5b9d\u77f3\u7ec4\u5408 &#8211; \u84dd\u6865\u4e91\u8bfe<\/h2>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"871\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075222-681b1136021d1.png\" width=\"554\" \/><\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"721\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075222-681b113616f68.png\" width=\"554\" \/><\/p>\n<p style=\"background-color:transparent\">&#xff08;\u8fd9\u9053\u9898\u6211\u53ea\u4f1a\u66b4\u529b&#xff0c;\u800c\u4e14\u6ca1\u62ff\u5230\u8be5\u62ff\u7684\u5206&#xff0c;\u522b\u63d0\u4e86&#xff0c;\u90fd\u662f\u6cea&#xff09;<\/p>\n<h3 style=\"background-color:transparent\">\u725b\u903c\u7684\u9898\u89e3&#xff1a;<\/h3>\n<p>#include &lt;bits\/stdc&#043;&#043;.h&gt;  \/\/ \u5305\u542b\u6240\u6709\u6807\u51c6\u5e93\u5934\u6587\u4ef6<\/p>\n<p>#define N 500010  \/\/ \u5b9a\u4e49\u5e38\u91cf N&#xff0c;\u8868\u793a\u6570\u7ec4\u7684\u6700\u5927\u5927\u5c0f<\/p>\n<p>int gem[N], num[N];  \/\/ \u5b9a\u4e49\u4e24\u4e2a\u6570\u7ec4&#xff1a;gem \u7528\u4e8e\u5b58\u50a8\u8f93\u5165\u7684\u5b9d\u77f3\u7f16\u53f7&#xff0c;num \u7528\u4e8e\u7edf\u8ba1\u6bcf\u79cd\u5b9d\u77f3\u7684\u6570\u91cf<\/p>\n<p>int main() {<br \/>\n    int n;<br \/>\n    scanf(&#034;%d&#034;, &amp;n);  \/\/ \u8f93\u5165\u6574\u6570 n&#xff0c;\u8868\u793a\u5b9d\u77f3\u7684\u6570\u91cf<\/p>\n<p>    int max &#061; -0x3f3f3f3f;  \/\/ \u521d\u59cb\u5316 max \u4e3a\u4e00\u4e2a\u5f88\u5c0f\u7684\u503c&#xff0c;\u7528\u4e8e\u8bb0\u5f55\u5b9d\u77f3\u7f16\u53f7\u7684\u6700\u5927\u503c<br \/>\n    for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n        scanf(&#034;%d&#034;, &amp;gem[i]);  \/\/ \u8f93\u5165\u6bcf\u4e2a\u5b9d\u77f3\u7684\u7f16\u53f7<br \/>\n        num[gem[i]]&#043;&#043;;  \/\/ \u7edf\u8ba1\u6bcf\u79cd\u5b9d\u77f3\u7684\u6570\u91cf<br \/>\n        if (gem[i] &gt; max) max &#061; gem[i];  \/\/ \u66f4\u65b0\u5b9d\u77f3\u7f16\u53f7\u7684\u6700\u5927\u503c<br \/>\n    }<\/p>\n<p>    \/\/ \u4ece\u6700\u5927\u503c\u5f00\u59cb&#xff0c;\u5c1d\u8bd5\u627e\u5230\u6ee1\u8db3\u6761\u4ef6\u7684\u4e09\u4e2a\u5b9d\u77f3<br \/>\n    for (int i &#061; max; i &gt;&#061; 1; i&#8211;) {  \/\/ i \u662f\u53ef\u80fd\u7684\u516c\u56e0\u6570<br \/>\n        int tmp[3], pos &#061; 0;  \/\/ tmp \u7528\u4e8e\u5b58\u50a8\u7b26\u5408\u6761\u4ef6\u7684\u5b9d\u77f3\u7f16\u53f7&#xff0c;pos \u7528\u4e8e\u8bb0\u5f55 tmp \u4e2d\u7684\u4f4d\u7f6e<br \/>\n        int cnt &#061; 0;  \/\/ cnt \u7528\u4e8e\u7edf\u8ba1\u7b26\u5408\u6761\u4ef6\u7684\u5b9d\u77f3\u6570\u91cf<\/p>\n<p>        \/\/ \u904d\u5386\u6240\u6709 i \u7684\u500d\u6570&#xff0c;\u68c0\u67e5\u662f\u5426\u5b58\u5728\u5bf9\u5e94\u7684\u5b9d\u77f3<br \/>\n        for (int j &#061; i; j &lt;&#061; max; j &#043;&#061; i) {  \/\/ j \u662f i \u7684\u500d\u6570<br \/>\n            if (num[j]) {  \/\/ \u5982\u679c\u5b9d\u77f3 j \u5b58\u5728<br \/>\n                cnt &#043;&#061; num[j];  \/\/ \u7edf\u8ba1\u5b9d\u77f3 j \u7684\u6570\u91cf<br \/>\n                for (int k &#061; 0; k &lt; num[j] &amp;&amp; pos &lt; 3; k&#043;&#043;) {  \/\/ \u5c06\u5b9d\u77f3 j \u52a0\u5165 tmp<br \/>\n                    tmp[pos&#043;&#043;] &#061; j;<br \/>\n                }<br \/>\n            }<br \/>\n            if (cnt &#061;&#061; 3) break;  \/\/ \u5982\u679c\u627e\u5230\u4e09\u4e2a\u5b9d\u77f3&#xff0c;\u8df3\u51fa\u5faa\u73af<br \/>\n        }<\/p>\n<p>        \/\/ \u5982\u679c\u627e\u5230\u4e09\u4e2a\u5b9d\u77f3&#xff0c;\u8f93\u51fa\u7ed3\u679c\u5e76\u7ed3\u675f\u7a0b\u5e8f<br \/>\n        if (cnt &#061;&#061; 3) {<br \/>\n            for (int j &#061; 0; j &lt; 3; j&#043;&#043;) {<br \/>\n                printf(&#034;%d &#034;, tmp[j]);  \/\/ \u8f93\u51fa\u4e09\u4e2a\u5b9d\u77f3\u7684\u7f16\u53f7<br \/>\n            }<br \/>\n            break;  \/\/ \u7ed3\u675f\u7a0b\u5e8f<br \/>\n        }<br \/>\n    }<\/p>\n<p>    return 0;  \/\/ \u7a0b\u5e8f\u7ed3\u675f<br \/>\n} <\/p>\n<h3>\u4ee3\u7801\u601d\u8def&#xff1a;\u00a0<\/h3>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"346\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075222-681b11362a7e8.png\" width=\"886\" \/><\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"792\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075222-681b113647ee8.png\" width=\"1020\" \/><\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"805\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075222-681b113697a37.png\" width=\"1044\" \/><\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"426\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075223-681b11373f953.png\" width=\"697\" \/><\/p>\n<\/p>\n<h2>\u516d\u30010\u6570\u5b57\u63a5\u9f99 &#8211; \u84dd\u6865\u4e91\u8bfe\u00a0<\/h2>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"884\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075223-681b113752262.png\" width=\"554\" \/><\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"747\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075223-681b113767653.png\" width=\"555\" \/><\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"404\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075223-681b11377ad53.png\" width=\"497\" \/><\/p>\n<h3>\u9898\u89e3\u4ee3\u7801&#xff1a;<\/h3>\n<p>#include &lt;bits\/stdc&#043;&#043;.h&gt;  \/\/ \u5305\u542b\u6240\u6709\u6807\u51c6\u5e93\u5934\u6587\u4ef6<br \/>\nusing namespace std;<\/p>\n<p>const int N &#061; 11; \/\/ \u5b9a\u4e49\u68cb\u76d8\u7684\u6700\u5927\u5927\u5c0f\u4e3a11\u00d711<br \/>\nint n, k; \/\/ n\u4e3a\u68cb\u76d8\u5927\u5c0f&#xff0c;k\u4e3a\u6570\u5b57\u5faa\u73af\u7684\u8303\u56f4<br \/>\nint g[N][N]; \/\/ \u5b58\u50a8\u68cb\u76d8\u4e0a\u7684\u6570\u5b57<br \/>\nint dx[8] &#061; {-1, -1, 0, 1, 1, 1, 0, -1}; \/\/ \u5b9a\u4e498\u4e2a\u65b9\u5411\u7684x\u5750\u6807\u504f\u79fb<br \/>\nint dy[8] &#061; {0, 1, 1, 1, 0, -1, -1, -1}; \/\/ \u5b9a\u4e498\u4e2a\u65b9\u5411\u7684y\u5750\u6807\u504f\u79fb<br \/>\nstring path; \/\/ \u5b58\u50a8\u8def\u5f84\u7684\u65b9\u5411\u7f16\u53f7<br \/>\nbool st[N][N]; \/\/ \u6807\u8bb0\u68cb\u76d8\u4e0a\u7684\u683c\u5b50\u662f\u5426\u88ab\u8bbf\u95ee\u8fc7<br \/>\nbool edge[N][N][N][N]; \/\/ \u68c0\u67e5\u8def\u5f84\u662f\u5426\u4ea4\u53c9<\/p>\n<p>\/\/ \u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u51fd\u6570&#xff0c;\u7528\u4e8e\u5bfb\u627e\u8def\u5f84<br \/>\nbool dfs(int a, int b) {<br \/>\n    \/\/ \u5982\u679c\u5230\u8fbe\u53f3\u4e0b\u89d2\u683c\u5b50&#xff0c;\u68c0\u67e5\u8def\u5f84\u957f\u5ea6\u662f\u5426\u4e3an*n-1&#xff08;\u56e0\u4e3a\u8d77\u70b9\u4e0d\u8ba1\u5165\u8def\u5f84&#xff09;<br \/>\n    if (a &#061;&#061; n &#8211; 1 &amp;&amp; b &#061;&#061; n &#8211; 1)<br \/>\n        return path.size() &#061;&#061; n * n &#8211; 1;<\/p>\n<p>    st[a][b] &#061; true; \/\/ \u6807\u8bb0\u5f53\u524d\u683c\u5b50\u5df2\u8bbf\u95ee<br \/>\n    for (int i &#061; 0; i &lt; 8; i&#043;&#043;) { \/\/ \u904d\u53868\u4e2a\u65b9\u5411<br \/>\n        int x &#061; a &#043; dx[i], y &#061; b &#043; dy[i]; \/\/ \u8ba1\u7b97\u76ee\u6807\u683c\u5b50\u7684\u5750\u6807<br \/>\n        \/\/ \u68c0\u67e5\u76ee\u6807\u683c\u5b50\u662f\u5426\u8d8a\u754c\u3001\u662f\u5426\u8bbf\u95ee\u8fc7\u3001\u6570\u5b57\u662f\u5426\u6ee1\u8db3\u5faa\u73af\u5e8f\u5217\u8981\u6c42<br \/>\n        if (x &lt; 0 || x &gt;&#061; n || y &lt; 0 || y &gt;&#061; n) continue;<br \/>\n        if (st[x][y]) continue;<br \/>\n        if (g[x][y] !&#061; (g[a][b] &#043; 1) % k) continue;<br \/>\n        \/\/ \u68c0\u67e5\u8def\u5f84\u662f\u5426\u4ea4\u53c9&#xff08;\u5bf9\u4e8e\u659c\u5411\u79fb\u52a8&#xff0c;\u68c0\u67e5\u662f\u5426\u6709\u53cd\u5411\u7684\u8def\u5f84&#xff09;<br \/>\n        if (i % 2 &amp;&amp; (edge[a][y][x][b] || edge[x][b][a][y])) continue;<\/p>\n<p>        edge[a][b][x][y] &#061; true; \/\/ \u6807\u8bb0\u8def\u5f84<br \/>\n        path &#043;&#061; i &#043; &#039;0&#039;; \/\/ \u5c06\u65b9\u5411\u7f16\u53f7\u52a0\u5165\u8def\u5f84<br \/>\n        if (dfs(x, y)) return true; \/\/ \u9012\u5f52\u641c\u7d22\u4e0b\u4e00\u4e2a\u683c\u5b50<br \/>\n        path.pop_back(); \/\/ \u56de\u6eaf&#xff0c;\u79fb\u9664\u8def\u5f84\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u65b9\u5411<br \/>\n        edge[a][b][x][y] &#061; false; \/\/ \u56de\u6eaf&#xff0c;\u53d6\u6d88\u8def\u5f84\u6807\u8bb0<br \/>\n    }<br \/>\n    st[a][b] &#061; false; \/\/ \u56de\u6eaf&#xff0c;\u53d6\u6d88\u5f53\u524d\u683c\u5b50\u7684\u8bbf\u95ee\u6807\u8bb0<br \/>\n    return false; \/\/ \u5982\u679c\u6240\u6709\u65b9\u5411\u90fd\u65e0\u6cd5\u5230\u8fbe\u7ec8\u70b9&#xff0c;\u8fd4\u56defalse<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    cin &gt;&gt; n &gt;&gt; k; \/\/ \u8f93\u5165\u68cb\u76d8\u5927\u5c0f\u548c\u6570\u5b57\u5faa\u73af\u8303\u56f4<br \/>\n    for (int i &#061; 0; i &lt; n; i&#043;&#043;) \/\/ \u8bfb\u53d6\u68cb\u76d8\u4e0a\u7684\u6570\u5b57<br \/>\n        for (int j &#061; 0; j &lt; n; j&#043;&#043;)<br \/>\n            cin &gt;&gt; g[i][j];<\/p>\n<p>    \/\/ \u4ece\u8d77\u70b9(0,0)\u5f00\u59cb\u641c\u7d22\u8def\u5f84<br \/>\n    if (!dfs(0, 0))<br \/>\n        cout &lt;&lt; -1 &lt;&lt; endl; \/\/ \u5982\u679c\u6ca1\u6709\u627e\u5230\u8def\u5f84&#xff0c;\u8f93\u51fa-1<br \/>\n    else<br \/>\n        cout &lt;&lt; path &lt;&lt; endl; \/\/ \u8f93\u51fa\u8def\u5f84\u7684\u65b9\u5411\u7f16\u53f7\u5e8f\u5217<\/p>\n<p>    return 0;<br \/>\n} <\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"567\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075223-681b11378b313.png\" width=\"755\" \/><\/p>\n<p>\u7f57\u52c7\u519b\u8001\u5e08\u7684\u5206\u6790&#xff1a;&#xff08;\u6709\u9053\u7406&#xff09;<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"161\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075223-681b1137a1e37.png\" width=\"880\" \/><\/p>\n<p>\u00a0<\/p>\n<h2>\u4e03\u30010\u62d4\u6cb3 &#8211; \u84dd\u6865\u4e91\u8bfe<\/h2>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"854\" src=\"2025-05-07fuphp0sltmu.png\" width=\"556\" \/><\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"731\" src=\"2025-05-07wkzh3fh4zjw.png\" width=\"555\" \/><\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"186\" src=\"2025-05-07z2cdh4rtdiu.png\" width=\"877\" \/><\/p>\n<h3>\u7b97\u6cd5\u4ee3\u7801&#xff08;20%\u66b4\u529b\u679a\u4e3e&#xff09;\u00a0<\/h3>\n<p>\/\/20%&#xff1a;\u66b4\u529b\u679a\u4e3e<br \/>\n#include&lt;bits\/stdc&#043;&#043;.h&gt;  \/\/ \u5305\u542b\u6240\u6709\u6807\u51c6\u5e93\u5934\u6587\u4ef6<br \/>\nusing namespace std;     \/\/ \u4f7f\u7528\u6807\u51c6\u547d\u540d\u7a7a\u95f4<\/p>\n<p>const int N &#061; 1e3 &#043; 100;  \/\/ \u5b9a\u4e49\u5e38\u91cf N&#xff0c;\u8868\u793a\u6570\u7ec4\u7684\u6700\u5927\u5927\u5c0f<br \/>\ntypedef long long ll;     \/\/ \u5b9a\u4e49 long long \u7c7b\u578b\u7684\u522b\u540d ll<br \/>\nll a[100];                \/\/ \u5b9a\u4e49\u6570\u7ec4 a&#xff0c;\u7528\u4e8e\u5b58\u50a8\u8f93\u5165\u7684\u6570\u5b57<\/p>\n<p>\/\/ \u8ba1\u7b97\u5b50\u6570\u7ec4\u548c\u7684\u51fd\u6570<br \/>\nll sum(int l, int r) {<br \/>\n    ll s &#061; 0;             \/\/ \u521d\u59cb\u5316\u5b50\u6570\u7ec4\u548c\u4e3a 0<br \/>\n    for (int i &#061; l; i &lt;&#061; r; i&#043;&#043;)  \/\/ \u904d\u5386\u5b50\u6570\u7ec4\u7684\u6bcf\u4e2a\u5143\u7d20<br \/>\n        s &#043;&#061; a[i];        \/\/ \u7d2f\u52a0\u5b50\u6570\u7ec4\u7684\u5143\u7d20<br \/>\n    return s;             \/\/ \u8fd4\u56de\u5b50\u6570\u7ec4\u7684\u548c<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    int n;                \/\/ \u5b9a\u4e49\u6574\u6570 n&#xff0c;\u8868\u793a\u6570\u7ec4\u7684\u5927\u5c0f<br \/>\n    cin &gt;&gt; n;             \/\/ \u8f93\u5165\u6570\u7ec4\u7684\u5927\u5c0f n<\/p>\n<p>    for (int i &#061; 1; i &lt;&#061; n; i&#043;&#043;)  \/\/ \u904d\u5386\u6570\u7ec4\u7684\u6bcf\u4e2a\u4f4d\u7f6e<br \/>\n        cin &gt;&gt; a[i];       \/\/ \u8f93\u5165\u6570\u7ec4\u7684\u6bcf\u4e2a\u5143\u7d20<\/p>\n<p>    ll ans &#061; 1e12;         \/\/ \u521d\u59cb\u5316\u7b54\u6848\u4e3a\u4e00\u4e2a\u5927\u503c&#xff08;1e12&#xff09;&#xff0c;\u7528\u4e8e\u5b58\u50a8\u6700\u5c0f\u7edd\u5bf9\u5dee<\/p>\n<p>    \/\/ \u66b4\u529b\u679a\u4e3e\u6240\u6709\u53ef\u80fd\u7684\u5b50\u6570\u7ec4\u5bf9<br \/>\n    for (int l1 &#061; 1; l1 &lt;&#061; n; l1&#043;&#043;) {        \/\/ \u679a\u4e3e\u7b2c\u4e00\u4e2a\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u4f4d\u7f6e l1<br \/>\n        for (int r1 &#061; l1; r1 &lt;&#061; n; r1&#043;&#043;) {    \/\/ \u679a\u4e3e\u7b2c\u4e00\u4e2a\u5b50\u6570\u7ec4\u7684\u7ed3\u675f\u4f4d\u7f6e r1<br \/>\n            for (int l2 &#061; r1 &#043; 1; l2 &lt;&#061; n; l2&#043;&#043;) {  \/\/ \u679a\u4e3e\u7b2c\u4e8c\u4e2a\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u4f4d\u7f6e l2<br \/>\n                for (int r2 &#061; l2; r2 &lt;&#061; n; r2&#043;&#043;) {  \/\/ \u679a\u4e3e\u7b2c\u4e8c\u4e2a\u5b50\u6570\u7ec4\u7684\u7ed3\u675f\u4f4d\u7f6e r2<br \/>\n                    \/\/ \u8ba1\u7b97\u4e24\u4e2a\u5b50\u6570\u7ec4\u548c\u7684\u7edd\u5bf9\u5dee&#xff0c;\u5e76\u66f4\u65b0\u6700\u5c0f\u503c<br \/>\n                    ans &#061; min(ans, abs(sum(l2, r2) &#8211; sum(l1, r1)));<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    cout &lt;&lt; ans;           \/\/ \u8f93\u51fa\u6700\u5c0f\u7edd\u5bf9\u5dee<br \/>\n    return 0;              \/\/ \u7a0b\u5e8f\u7ed3\u675f<br \/>\n} <\/p>\n<h3>\u00a0\u7b97\u6cd5\u4ee3\u7801&#xff08;40%\u66b4\u529b\u679a\u4e3e&#043;\u524d\u7f00\u548c\u4f18\u5316&#xff09;\u00a0<\/h3>\n<p>#include&lt;bits\/stdc&#043;&#043;.h&gt;  \/\/ \u5305\u542b\u6240\u6709\u6807\u51c6\u5e93\u5934\u6587\u4ef6<br \/>\nusing namespace std;     \/\/ \u4f7f\u7528\u6807\u51c6\u547d\u540d\u7a7a\u95f4<\/p>\n<p>const int N &#061; 1e3 &#043; 100;  \/\/ \u5b9a\u4e49\u5e38\u91cf N&#xff0c;\u8868\u793a\u6570\u7ec4\u7684\u6700\u5927\u5927\u5c0f<br \/>\ntypedef long long ll;     \/\/ \u5b9a\u4e49 long long \u7c7b\u578b\u7684\u522b\u540d ll<br \/>\nll a[N], prefix[N];       \/\/ \u5b9a\u4e49\u6570\u7ec4 a \u548c\u524d\u7f00\u548c\u6570\u7ec4 prefix<\/p>\n<p>\/\/ \u8ba1\u7b97\u5b50\u6570\u7ec4\u548c\u7684\u51fd\u6570<br \/>\nll sum(int l, int r) {<br \/>\n    return prefix[r] &#8211; prefix[l &#8211; 1];  \/\/ \u8fd4\u56de\u5b50\u6570\u7ec4 [l, r] \u7684\u548c<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    int n;                \/\/ \u5b9a\u4e49\u6574\u6570 n&#xff0c;\u8868\u793a\u6570\u7ec4\u7684\u5927\u5c0f<br \/>\n    cin &gt;&gt; n;             \/\/ \u8f93\u5165\u6570\u7ec4\u7684\u5927\u5c0f n<\/p>\n<p>    \/\/ \u8bfb\u53d6\u6570\u7ec4\u5e76\u8ba1\u7b97\u524d\u7f00\u548c<br \/>\n    for (int i &#061; 1; i &lt;&#061; n; i&#043;&#043;) {<br \/>\n        cin &gt;&gt; a[i];                \/\/ \u8f93\u5165\u6570\u7ec4\u7684\u6bcf\u4e2a\u5143\u7d20<br \/>\n        prefix[i] &#061; prefix[i &#8211; 1] &#043; a[i];  \/\/ \u8ba1\u7b97\u524d\u7f00\u548c<br \/>\n    }<\/p>\n<p>    ll ans &#061; 1e12;         \/\/ \u521d\u59cb\u5316\u7b54\u6848\u4e3a\u4e00\u4e2a\u5927\u503c&#xff08;1e12&#xff09;&#xff0c;\u7528\u4e8e\u5b58\u50a8\u6700\u5c0f\u7edd\u5bf9\u5dee<\/p>\n<p>    \/\/ \u679a\u4e3e\u6240\u6709\u5b50\u6570\u7ec4\u5bf9<br \/>\n    for (int l1 &#061; 1; l1 &lt;&#061; n; l1&#043;&#043;) {        \/\/ \u679a\u4e3e\u7b2c\u4e00\u4e2a\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u4f4d\u7f6e l1<br \/>\n        for (int r1 &#061; l1; r1 &lt;&#061; n; r1&#043;&#043;) {    \/\/ \u679a\u4e3e\u7b2c\u4e00\u4e2a\u5b50\u6570\u7ec4\u7684\u7ed3\u675f\u4f4d\u7f6e r1<br \/>\n            ll sum1 &#061; sum(l1, r1);             \/\/ \u8ba1\u7b97\u7b2c\u4e00\u4e2a\u5b50\u6570\u7ec4\u7684\u548c<br \/>\n            for (int l2 &#061; r1 &#043; 1; l2 &lt;&#061; n; l2&#043;&#043;) {  \/\/ \u679a\u4e3e\u7b2c\u4e8c\u4e2a\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u4f4d\u7f6e l2<br \/>\n                for (int r2 &#061; l2; r2 &lt;&#061; n; r2&#043;&#043;) {  \/\/ \u679a\u4e3e\u7b2c\u4e8c\u4e2a\u5b50\u6570\u7ec4\u7684\u7ed3\u675f\u4f4d\u7f6e r2<br \/>\n                    ll sum2 &#061; sum(l2, r2);           \/\/ \u8ba1\u7b97\u7b2c\u4e8c\u4e2a\u5b50\u6570\u7ec4\u7684\u548c<br \/>\n                    ans &#061; min(ans, abs(sum2 &#8211; sum1));  \/\/ \u66f4\u65b0\u6700\u5c0f\u7edd\u5bf9\u5dee<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    cout &lt;&lt; ans;           \/\/ \u8f93\u51fa\u6700\u5c0f\u7edd\u5bf9\u5dee<br \/>\n    return 0;              \/\/ \u7a0b\u5e8f\u7ed3\u675f<br \/>\n} <\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"450\" src=\"2025-05-07ce1eulpxh2h.png\" width=\"706\" \/><\/p>\n<h3>\u9006\u5929\u9898\u89e3&#xff1a;&#xff08;\u771f\u7684\u60f3\u4e0d\u51fa\u6765&#xff0c;\u6211\u662f\u4e2a\u53ea\u4f1a\u66b4\u529b\u7684fw&#xff09;<\/h3>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"104\" src=\"2025-05-07vh5m2cliqdb.png\" width=\"1175\" \/><\/p>\n<p>#include&lt;bits\/stdc&#043;&#043;.h&gt;  \/\/ \u5305\u542b\u6240\u6709\u6807\u51c6\u5e93\u5934\u6587\u4ef6<br \/>\nusing namespace std;     \/\/ \u4f7f\u7528\u6807\u51c6\u547d\u540d\u7a7a\u95f4<\/p>\n<p>const int N &#061; 1e3 &#043; 10;  \/\/ \u5b9a\u4e49\u5e38\u91cf N&#xff0c;\u8868\u793a\u6570\u7ec4\u7684\u6700\u5927\u5927\u5c0f<br \/>\nlong long a[N];          \/\/ \u5b9a\u4e49\u6570\u7ec4 a&#xff0c;\u7528\u4e8e\u5b58\u50a8\u524d\u7f00\u548c<br \/>\nint n;                   \/\/ \u5b9a\u4e49\u6574\u6570 n&#xff0c;\u8868\u793a\u6570\u7ec4\u7684\u5927\u5c0f<br \/>\nmultiset&lt;long long&gt; s;   \/\/ \u5b9a\u4e49 multiset&#xff0c;\u7528\u4e8e\u5b58\u50a8\u6240\u6709\u53ef\u80fd\u7684\u5b50\u6570\u7ec4\u548c<\/p>\n<p>\/\/ \u81ea\u5b9a\u4e49\u51fd\u6570&#xff0c;\u8fd4\u56de\u4e24\u4e2a\u6570\u4e2d\u7684\u8f83\u5c0f\u503c<br \/>\nlong long minn(long long a, long long b) {<br \/>\n    if (a &lt; b) return a;<br \/>\n    else return b;<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);  \/\/ \u53d6\u6d88\u540c\u6b65\u6d41&#xff0c;\u52a0\u901f\u8f93\u5165\u8f93\u51fa<br \/>\n    cin &gt;&gt; n;  \/\/ \u8f93\u5165\u6570\u7ec4\u7684\u5927\u5c0f n<\/p>\n<p>    \/\/ \u8bfb\u53d6\u6570\u7ec4\u5e76\u6784\u9020\u524d\u7f00\u548c<br \/>\n    for (int i &#061; 1; i &lt;&#061; n; i&#043;&#043;) {<br \/>\n        cin &gt;&gt; a[i];<br \/>\n        a[i] &#043;&#061; a[i &#8211; 1];  \/\/ \u8ba1\u7b97\u524d\u7f00\u548c<br \/>\n    }<\/p>\n<p>    \/\/ \u679a\u4e3e\u6240\u6709\u53ef\u80fd\u7684\u5b50\u6570\u7ec4\u548c&#xff0c;\u5e76\u5c06\u5176\u63d2\u5165 multiset<br \/>\n    for (int i &#061; 1; i &lt;&#061; n; i&#043;&#043;) {<br \/>\n        for (int j &#061; i; j &lt;&#061; n; j&#043;&#043;) {<br \/>\n            s.insert(a[j] &#8211; a[i &#8211; 1]);  \/\/ \u8ba1\u7b97\u5b50\u6570\u7ec4 [i, j] \u7684\u548c&#xff0c;\u5e76\u63d2\u5165 multiset<br \/>\n        }<br \/>\n    }<\/p>\n<p>    long long res &#061; 1e9;  \/\/ \u521d\u59cb\u5316\u7ed3\u679c\u4e3a\u4e00\u4e2a\u5927\u503c&#xff08;1e9&#xff09;&#xff0c;\u7528\u4e8e\u5b58\u50a8\u6700\u5c0f\u7edd\u5bf9\u5dee<\/p>\n<p>    \/\/ \u904d\u5386\u6240\u6709\u53ef\u80fd\u7684\u7b2c\u4e00\u4e2a\u533a\u95f4\u7684\u53f3\u7aef\u70b9 i<br \/>\n    for (int i &#061; 1; i &lt; n; i&#043;&#043;) {<br \/>\n        \/\/ \u5220\u9664\u4ee5 i \u4f5c\u4e3a\u53f3\u7aef\u70b9\u7684\u6240\u6709\u5b50\u6570\u7ec4\u548c<br \/>\n        for (int j &#061; i; j &lt;&#061; n; j&#043;&#043;) {<br \/>\n            auto k &#061; a[j] &#8211; a[i &#8211; 1];  \/\/ \u8ba1\u7b97\u5b50\u6570\u7ec4 [i, j] \u7684\u548c<br \/>\n            s.erase(s.find(k));        \/\/ \u4ece multiset \u4e2d\u5220\u9664\u8be5\u548c<br \/>\n        }<\/p>\n<p>        \/\/ \u904d\u5386\u6240\u6709\u53ef\u80fd\u7684\u7b2c\u4e00\u4e2a\u533a\u95f4\u7684\u5de6\u7aef\u70b9 j<br \/>\n        for (int j &#061; 1; j &lt;&#061; i; j&#043;&#043;) {<br \/>\n            auto k &#061; a[i] &#8211; a[j &#8211; 1];  \/\/ \u8ba1\u7b97\u7b2c\u4e00\u4e2a\u5b50\u6570\u7ec4 [j, i] \u7684\u548c<\/p>\n<p>            \/\/ \u5728 multiset \u4e2d\u67e5\u627e\u6700\u63a5\u8fd1 k \u7684\u503c<br \/>\n            auto p &#061; s.lower_bound(k);  \/\/ \u627e\u5230\u7b2c\u4e00\u4e2a &gt;&#061; k \u7684\u503c<br \/>\n            if (p !&#061; s.end()) {<br \/>\n                res &#061; minn(res, abs(*p &#8211; k));  \/\/ \u66f4\u65b0\u6700\u5c0f\u7edd\u5bf9\u5dee<br \/>\n            }<br \/>\n            if (p !&#061; s.begin()) {<br \/>\n                p&#8211;;  \/\/ \u627e\u5230\u7b2c\u4e00\u4e2a &lt; k \u7684\u503c<br \/>\n                res &#061; minn(res, abs(*p &#8211; k));  \/\/ \u66f4\u65b0\u6700\u5c0f\u7edd\u5bf9\u5dee<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    cout &lt;&lt; res &lt;&lt; endl;  \/\/ \u8f93\u51fa\u6700\u5c0f\u7edd\u5bf9\u5dee<br \/>\n    return 0;             \/\/ \u7a0b\u5e8f\u7ed3\u675f<br \/>\n} <\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"714\" src=\"2025-05-07rzcxsmhnyh3.png\" width=\"799\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb7.7k\u6b21\uff0c\u70b9\u8d5e87\u6b21\uff0c\u6536\u85cf161\u6b21\u3002\u84dd\u6865\u676f\u771f\u9898\u5237\u9898\u2014\u2014\u7b2c\u5341\u4e94\u5c4a\u84dd\u6865\u676f\u5927\u8d5b\u8f6f\u4ef6\u8d5b\u7701\u8d5bC\/C++ \u5927\u5b66 B \u7ec4<\/p>\n","protected":false},"author":2,"featured_media":36090,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,174,729],"topic":[],"class_list":{"0":"post-36110","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","6":"hentry","7":"category-server","8":"tag-c","10":"tag-729"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u84dd\u6865\u676f\u5237\u9898\u2014\u2014\u7b2c\u5341\u4e94\u5c4a\u84dd\u6865\u676f\u5927\u8d5b\u8f6f\u4ef6\u8d5b\u7701\u8d5bC\/C++ \u5927\u5b66 B \u7ec4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/36110.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u84dd\u6865\u676f\u5237\u9898\u2014\u2014\u7b2c\u5341\u4e94\u5c4a\u84dd\u6865\u676f\u5927\u8d5b\u8f6f\u4ef6\u8d5b\u7701\u8d5bC\/C++ \u5927\u5b66 B \u7ec4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb7.7k\u6b21\uff0c\u70b9\u8d5e87\u6b21\uff0c\u6536\u85cf161\u6b21\u3002\u84dd\u6865\u676f\u771f\u9898\u5237\u9898\u2014\u2014\u7b2c\u5341\u4e94\u5c4a\u84dd\u6865\u676f\u5927\u8d5b\u8f6f\u4ef6\u8d5b\u7701\u8d5bC\/C++ \u5927\u5b66 B \u7ec4\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/36110.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-07T07:52:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075221-681b11354f672.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/36110.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/36110.html\",\"name\":\"\u84dd\u6865\u676f\u5237\u9898\u2014\u2014\u7b2c\u5341\u4e94\u5c4a\u84dd\u6865\u676f\u5927\u8d5b\u8f6f\u4ef6\u8d5b\u7701\u8d5bC\/C++ \u5927\u5b66 B \u7ec4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-07T07:52:24+00:00\",\"dateModified\":\"2025-05-07T07:52:24+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/36110.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/36110.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/36110.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u84dd\u6865\u676f\u5237\u9898\u2014\u2014\u7b2c\u5341\u4e94\u5c4a\u84dd\u6865\u676f\u5927\u8d5b\u8f6f\u4ef6\u8d5b\u7701\u8d5bC\/C++ \u5927\u5b66 B \u7ec4\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u84dd\u6865\u676f\u5237\u9898\u2014\u2014\u7b2c\u5341\u4e94\u5c4a\u84dd\u6865\u676f\u5927\u8d5b\u8f6f\u4ef6\u8d5b\u7701\u8d5bC\/C++ \u5927\u5b66 B \u7ec4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/36110.html","og_locale":"zh_CN","og_type":"article","og_title":"\u84dd\u6865\u676f\u5237\u9898\u2014\u2014\u7b2c\u5341\u4e94\u5c4a\u84dd\u6865\u676f\u5927\u8d5b\u8f6f\u4ef6\u8d5b\u7701\u8d5bC\/C++ \u5927\u5b66 B \u7ec4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb7.7k\u6b21\uff0c\u70b9\u8d5e87\u6b21\uff0c\u6536\u85cf161\u6b21\u3002\u84dd\u6865\u676f\u771f\u9898\u5237\u9898\u2014\u2014\u7b2c\u5341\u4e94\u5c4a\u84dd\u6865\u676f\u5927\u8d5b\u8f6f\u4ef6\u8d5b\u7701\u8d5bC\/C++ \u5927\u5b66 B \u7ec4","og_url":"https:\/\/www.wsisp.com\/helps\/36110.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-07T07:52:24+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250507075221-681b11354f672.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/36110.html","url":"https:\/\/www.wsisp.com\/helps\/36110.html","name":"\u84dd\u6865\u676f\u5237\u9898\u2014\u2014\u7b2c\u5341\u4e94\u5c4a\u84dd\u6865\u676f\u5927\u8d5b\u8f6f\u4ef6\u8d5b\u7701\u8d5bC\/C++ \u5927\u5b66 B \u7ec4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-07T07:52:24+00:00","dateModified":"2025-05-07T07:52:24+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/36110.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/36110.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/36110.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u84dd\u6865\u676f\u5237\u9898\u2014\u2014\u7b2c\u5341\u4e94\u5c4a\u84dd\u6865\u676f\u5927\u8d5b\u8f6f\u4ef6\u8d5b\u7701\u8d5bC\/C++ \u5927\u5b66 B \u7ec4"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/36110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=36110"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/36110\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/36090"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=36110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=36110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=36110"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=36110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}