{"id":52894,"date":"2025-08-11T21:14:21","date_gmt":"2025-08-11T13:14:21","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/52894.html"},"modified":"2025-08-11T21:14:21","modified_gmt":"2025-08-11T13:14:21","slug":"%e6%b4%9b%e8%b0%b7-p1596-usaco10oct-lake-counting-s-%e6%99%ae%e5%8f%8a","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/52894.html","title":{"rendered":"\u6d1b\u8c37 P1596 [USACO10OCT] Lake Counting S-\u666e\u53ca-"},"content":{"rendered":"<h3>\u9898\u76ee\u63cf\u8ff0<\/h3>\n<p>\u7531\u4e8e\u6700\u8fd1\u7684\u964d\u96e8&#xff0c;\u6c34\u5728\u519c\u592b\u7ea6\u7ff0\u7684\u7530\u5730\u91cc\u79ef\u805a\u4e86\u3002\u7530\u5730\u53ef\u4ee5\u8868\u793a\u4e3a\u4e00\u4e2a <span class=\"katex--inline\"><span class=\"katex\"><span class=\"katex-mathml\">N\u00d7MN \\\\times M<\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.7667em;vertical-align: -0.0833em\"><\/span><span class=\"mord mathnormal\" style=\"margin-right: 0.109em\">N<\/span><span class=\"mspace\" style=\"margin-right: 0.2222em\"><\/span><span class=\"mbin\">\u00d7<\/span><span class=\"mspace\" style=\"margin-right: 0.2222em\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 0.6833em\"><\/span><span class=\"mord mathnormal\" style=\"margin-right: 0.109em\">M<\/span><\/span><\/span><\/span><\/span> \u7684\u77e9\u5f62&#xff08;<span class=\"katex--inline\"><span class=\"katex\"><span class=\"katex-mathml\">1\u2264N\u22641001 \\\\leq N \\\\leq 100<\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.7804em;vertical-align: -0.136em\"><\/span><span class=\"mord\">1<\/span><span class=\"mspace\" style=\"margin-right: 0.2778em\"><\/span><span class=\"mrel\">\u2264<\/span><span class=\"mspace\" style=\"margin-right: 0.2778em\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 0.8193em;vertical-align: -0.136em\"><\/span><span class=\"mord mathnormal\" style=\"margin-right: 0.109em\">N<\/span><span class=\"mspace\" style=\"margin-right: 0.2778em\"><\/span><span class=\"mrel\">\u2264<\/span><span class=\"mspace\" style=\"margin-right: 0.2778em\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 0.6444em\"><\/span><span class=\"mord\">100<\/span><\/span><\/span><\/span><\/span>&#xff1b;<span class=\"katex--inline\"><span class=\"katex\"><span class=\"katex-mathml\">1\u2264M\u22641001 \\\\leq M \\\\leq 100<\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.7804em;vertical-align: -0.136em\"><\/span><span class=\"mord\">1<\/span><span class=\"mspace\" style=\"margin-right: 0.2778em\"><\/span><span class=\"mrel\">\u2264<\/span><span class=\"mspace\" style=\"margin-right: 0.2778em\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 0.8193em;vertical-align: -0.136em\"><\/span><span class=\"mord mathnormal\" style=\"margin-right: 0.109em\">M<\/span><span class=\"mspace\" style=\"margin-right: 0.2778em\"><\/span><span class=\"mrel\">\u2264<\/span><span class=\"mspace\" style=\"margin-right: 0.2778em\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 0.6444em\"><\/span><span class=\"mord\">100<\/span><\/span><\/span><\/span><\/span>&#xff09;\u3002\u6bcf\u4e2a\u65b9\u683c\u4e2d\u8981\u4e48\u662f\u6c34&#xff08;W&#xff09;&#xff0c;\u8981\u4e48\u662f\u5e72\u5730&#xff08;.&#xff09;\u3002\u519c\u592b\u7ea6\u7ff0\u60f3\u8981\u5f04\u6e05\u695a\u4ed6\u7684\u7530\u5730\u91cc\u5f62\u6210\u4e86\u591a\u5c11\u4e2a\u6c34\u5858\u3002\u4e00\u4e2a\u6c34\u5858\u662f\u7531\u8fde\u901a\u7684\u6c34\u65b9\u683c\u7ec4\u6210\u7684&#xff0c;\u5176\u4e2d\u4e00\u4e2a\u65b9\u683c\u88ab\u8ba4\u4e3a\u4e0e\u5b83\u7684\u516b\u4e2a\u90bb\u5c45\u76f8\u90bb\u3002\u7ed9\u5b9a\u519c\u592b\u7ea6\u7ff0\u7530\u5730\u7684\u793a\u610f\u56fe&#xff0c;\u786e\u5b9a\u4ed6\u6709\u591a\u5c11\u4e2a\u6c34\u5858\u3002<\/p>\n<h3>\u8f93\u5165\u683c\u5f0f<\/h3>\n<p>\u7b2c <span class=\"katex--inline\"><span class=\"katex\"><span class=\"katex-mathml\">11<\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.6444em\"><\/span><span class=\"mord\">1<\/span><\/span><\/span><\/span><\/span> \u884c&#xff1a;\u4e24\u4e2a\u7528\u7a7a\u683c\u5206\u9694\u7684\u6574\u6570&#xff1a;<span class=\"katex--inline\"><span class=\"katex\"><span class=\"katex-mathml\">NN<\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.6833em\"><\/span><span class=\"mord mathnormal\" style=\"margin-right: 0.109em\">N<\/span><\/span><\/span><\/span><\/span> \u548c <span class=\"katex--inline\"><span class=\"katex\"><span class=\"katex-mathml\">MM<\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.6833em\"><\/span><span class=\"mord mathnormal\" style=\"margin-right: 0.109em\">M<\/span><\/span><\/span><\/span><\/span>\u3002<\/p>\n<p>\u7b2c <span class=\"katex--inline\"><span class=\"katex\"><span class=\"katex-mathml\">22<\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.6444em\"><\/span><span class=\"mord\">2<\/span><\/span><\/span><\/span><\/span> \u884c\u5230\u7b2c <span class=\"katex--inline\"><span class=\"katex\"><span class=\"katex-mathml\">N&#043;1N&#043;1<\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.7667em;vertical-align: -0.0833em\"><\/span><span class=\"mord mathnormal\" style=\"margin-right: 0.109em\">N<\/span><span class=\"mspace\" style=\"margin-right: 0.2222em\"><\/span><span class=\"mbin\">&#043;<\/span><span class=\"mspace\" style=\"margin-right: 0.2222em\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 0.6444em\"><\/span><span class=\"mord\">1<\/span><\/span><\/span><\/span><\/span> \u884c&#xff1a;\u6bcf\u884c <span class=\"katex--inline\"><span class=\"katex\"><span class=\"katex-mathml\">MM<\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.6833em\"><\/span><span class=\"mord mathnormal\" style=\"margin-right: 0.109em\">M<\/span><\/span><\/span><\/span><\/span> \u4e2a\u5b57\u7b26&#xff0c;\u8868\u793a\u519c\u592b\u7ea6\u7ff0\u7530\u5730\u7684\u4e00\u884c\u3002<\/p>\n<p>\u6bcf\u4e2a\u5b57\u7b26\u8981\u4e48\u662f W&#xff0c;\u8981\u4e48\u662f .\u3002<\/p>\n<p>\u5b57\u7b26\u4e4b\u95f4\u6ca1\u6709\u7a7a\u683c\u3002<\/p>\n<h3>\u8f93\u51fa\u683c\u5f0f<\/h3>\n<p>\u7b2c <span class=\"katex--inline\"><span class=\"katex\"><span class=\"katex-mathml\">11<\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.6444em\"><\/span><span class=\"mord\">1<\/span><\/span><\/span><\/span><\/span> \u884c&#xff1a;\u519c\u592b\u7ea6\u7ff0\u7530\u5730\u4e2d\u7684\u6c34\u5858\u6570\u91cf\u3002<\/p>\n<h3>\u8f93\u5165\u8f93\u51fa\u6837\u4f8b #1<\/h3>\n<h4>\u8f93\u5165 #1<\/h4>\n<p>10 12<br \/>\nW&#8230;&#8230;..WW.<br \/>\n.WWW&#8230;..WWW<br \/>\n&#8230;.WW&#8230;WW.<br \/>\n&#8230;&#8230;&#8230;WW.<br \/>\n&#8230;&#8230;&#8230;W..<br \/>\n..W&#8230;&#8230;W..<br \/>\n.W.W&#8230;..WW.<br \/>\nW.W.W&#8230;..W.<br \/>\n.W.W&#8230;&#8230;W.<br \/>\n..W&#8230;&#8230;.W.<\/p>\n<h4>\u8f93\u51fa #1<\/h4>\n<p>3<\/p>\n<h3>\u8bf4\u660e\/\u63d0\u793a<\/h3>\n<p>\u8f93\u51fa\u8be6\u60c5&#xff1a;\u5171\u6709\u4e09\u4e2a\u6c34\u5858&#xff1a;\u4e00\u4e2a\u5728\u5de6\u4e0a\u89d2&#xff0c;\u4e00\u4e2a\u5728\u5de6\u4e0b\u89d2&#xff0c;\u8fd8\u6709\u4e00\u4e2a\u6cbf\u7740\u53f3\u4fa7\u3002<\/p>\n<p>&#xff08;\u7531 ChatGPT 4o \u7ffb\u8bd1&#xff09;<\/p>\n<h3>solution<\/h3>\n<p>\u601d\u8def&#xff1a;\u7528 dfs \u641c\u7d22 W \u4ee5\u53ca\u5468\u56f4\u56db\u4e2a\u65b9\u5411\u7684 W&#xff0c;\u72ec\u7acb\u641c\u7d22&#xff08;\u5373\u4e0d\u662f\u4ece\u5176\u5b83W\u9012\u5f52\u641c\u7d22&#xff09;\u6b21\u6570\u5c31\u662f\u6c34\u5858\u6c34\u91cf<\/p>\n<h4>\u4ee3\u7801<\/h4>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;sstream&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;iostream&#034;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;math.h&#034;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;algorithm&#034;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;string.h&#034;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;unordered_set&#034;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;deque&#034;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;stack&#034;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;queue&#034;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;vector&#034;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;unordered_map&#034;<\/span><\/span><\/p>\n<p><span class=\"token keyword\">using<\/span> <span class=\"token keyword\">namespace<\/span> std<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">char<\/span> c<span class=\"token punctuation\">[<\/span><span class=\"token number\">100<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">100<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">bool<\/span> vis<span class=\"token punctuation\">[<\/span><span class=\"token number\">100<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">100<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> n<span class=\"token punctuation\">,<\/span> m<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> dx<span class=\"token punctuation\">[<\/span><span class=\"token number\">8<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> dy<span class=\"token punctuation\">[<\/span><span class=\"token number\">8<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token function\">f<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> j<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    vis<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> k <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> k <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">8<\/span><span class=\"token punctuation\">;<\/span> k<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>i <span class=\"token operator\">&#043;<\/span> dx<span class=\"token punctuation\">[<\/span>k<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&gt;&#061;<\/span> <span class=\"token number\">0<\/span> <span class=\"token operator\">&amp;&amp;<\/span> i <span class=\"token operator\">&#043;<\/span> dx<span class=\"token punctuation\">[<\/span>k<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&lt;<\/span> n <span class=\"token operator\">&amp;&amp;<\/span> j <span class=\"token operator\">&#043;<\/span> dy<span class=\"token punctuation\">[<\/span>k<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&gt;&#061;<\/span> <span class=\"token number\">0<\/span> <span class=\"token operator\">&amp;&amp;<\/span> j <span class=\"token operator\">&#043;<\/span> dy<span class=\"token punctuation\">[<\/span>k<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&lt;&#061;<\/span> m <span class=\"token operator\">&amp;&amp;<\/span> <span class=\"token operator\">!<\/span>vis<span class=\"token punctuation\">[<\/span>i <span class=\"token operator\">&#043;<\/span> dx<span class=\"token punctuation\">[<\/span>k<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>j <span class=\"token operator\">&#043;<\/span> dy<span class=\"token punctuation\">[<\/span>k<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&amp;&amp;<\/span> c<span class=\"token punctuation\">[<\/span>i <span class=\"token operator\">&#043;<\/span> dx<span class=\"token punctuation\">[<\/span>k<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>j <span class=\"token operator\">&#043;<\/span> dy<span class=\"token punctuation\">[<\/span>k<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#039;W&#039;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token function\">f<\/span><span class=\"token punctuation\">(<\/span>i <span class=\"token operator\">&#043;<\/span> dx<span class=\"token punctuation\">[<\/span>k<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> j <span class=\"token operator\">&#043;<\/span> dy<span class=\"token punctuation\">[<\/span>k<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    cin <span class=\"token operator\">&gt;&gt;<\/span> n <span class=\"token operator\">&gt;&gt;<\/span> m<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> n<span class=\"token punctuation\">;<\/span> i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> j <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> j <span class=\"token operator\">&lt;<\/span> m<span class=\"token punctuation\">;<\/span> j<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> cin <span class=\"token operator\">&gt;&gt;<\/span> c<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">int<\/span> s <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> n<span class=\"token punctuation\">;<\/span> i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> j <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> j <span class=\"token operator\">&lt;<\/span> m<span class=\"token punctuation\">;<\/span> j<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span>vis<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&amp;&amp;<\/span> c<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#039;W&#039;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n                s<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n                <span class=\"token function\">f<\/span><span class=\"token punctuation\">(<\/span>i<span class=\"token punctuation\">,<\/span> j<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><\/p>\n<p>    cout <span class=\"token operator\">&lt;&lt;<\/span> s<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>\u7ed3\u679c<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250811131419-6899ecabc5aed.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb200\u6b21\u3002\u519c\u592b\u7ea6\u7ff0\u60f3\u8981\u5f04\u6e05\u695a\u4ed6\u7684\u7530\u5730\u91cc\u5f62\u6210\u4e86\u591a\u5c11\u4e2a\u6c34\u5858\u3002\u4e00\u4e2a\u6c34\u5858\u662f\u7531\u8fde\u901a\u7684\u6c34\u65b9\u683c\u7ec4\u6210\u7684\uff0c\u5176\u4e2d\u4e00\u4e2a\u65b9\u683c\u88ab\u8ba4\u4e3a\u4e0e\u5b83\u7684\u516b\u4e2a\u90bb\u5c45\u76f8\u90bb\u3002\u7ed9\u5b9a\u519c\u592b\u7ea6\u7ff0\u7530\u5730\u7684\u793a\u610f\u56fe\uff0c\u786e\u5b9a\u4ed6\u6709\u591a\u5c11\u4e2a\u6c34\u5858\u3002\u601d\u8def\uff1a\u7528 dfs \u641c\u7d22 W \u4ee5\u53ca\u5468\u56f4\u56db\u4e2a\u65b9\u5411\u7684 W\uff0c\u72ec\u7acb\u641c\u7d22\uff08\u5373\u4e0d\u662f\u4ece\u5176\u5b83W\u9012\u5f52\u641c\u7d22\uff09\u6b21\u6570\u5c31\u662f\u6c34\u5858\u6c34\u91cf\u3002\u8f93\u51fa\u8be6\u60c5\uff1a\u5171\u6709\u4e09\u4e2a\u6c34\u5858\uff1a\u4e00\u4e2a\u5728\u5de6\u4e0a\u89d2\uff0c\u4e00\u4e2a\u5728\u5de6\u4e0b\u89d2\uff0c\u8fd8\u6709\u4e00\u4e2a\u6cbf\u7740\u53f3\u4fa7\u3002\u7531\u4e8e\u6700\u8fd1\u7684\u964d\u96e8\uff0c\u6c34\u5728\u519c\u592b\u7ea6\u7ff0\u7684\u7530\u5730\u91cc\u79ef\u805a\u4e86\u3002\u4e2a\u5b57\u7b26\uff0c\u8868\u793a\u519c\u592b\u7ea6\u7ff0\u7530\u5730\u7684\u4e00\u884c\u3002\uff08\u7531 ChatGPT 4o \u7ffb\u8bd1\uff09\u884c\uff1a\u519c\u592b\u7ea6\u7ff0\u7530\u5730\u4e2d\u7684\u6c34\u5858\u6570\u91cf\u3002\u6bcf\u4e2a\u65b9\u683c\u4e2d\u8981\u4e48\u662f\u6c34\uff08<\/p>\n","protected":false},"author":2,"featured_media":52893,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,1813,3784,427],"topic":[],"class_list":["post-52894","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-1813","tag-3784","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u6d1b\u8c37 P1596 [USACO10OCT] Lake Counting S-\u666e\u53ca- \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\/52894.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u6d1b\u8c37 P1596 [USACO10OCT] Lake Counting S-\u666e\u53ca- \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb200\u6b21\u3002\u519c\u592b\u7ea6\u7ff0\u60f3\u8981\u5f04\u6e05\u695a\u4ed6\u7684\u7530\u5730\u91cc\u5f62\u6210\u4e86\u591a\u5c11\u4e2a\u6c34\u5858\u3002\u4e00\u4e2a\u6c34\u5858\u662f\u7531\u8fde\u901a\u7684\u6c34\u65b9\u683c\u7ec4\u6210\u7684\uff0c\u5176\u4e2d\u4e00\u4e2a\u65b9\u683c\u88ab\u8ba4\u4e3a\u4e0e\u5b83\u7684\u516b\u4e2a\u90bb\u5c45\u76f8\u90bb\u3002\u7ed9\u5b9a\u519c\u592b\u7ea6\u7ff0\u7530\u5730\u7684\u793a\u610f\u56fe\uff0c\u786e\u5b9a\u4ed6\u6709\u591a\u5c11\u4e2a\u6c34\u5858\u3002\u601d\u8def\uff1a\u7528 dfs \u641c\u7d22 W \u4ee5\u53ca\u5468\u56f4\u56db\u4e2a\u65b9\u5411\u7684 W\uff0c\u72ec\u7acb\u641c\u7d22\uff08\u5373\u4e0d\u662f\u4ece\u5176\u5b83W\u9012\u5f52\u641c\u7d22\uff09\u6b21\u6570\u5c31\u662f\u6c34\u5858\u6c34\u91cf\u3002\u8f93\u51fa\u8be6\u60c5\uff1a\u5171\u6709\u4e09\u4e2a\u6c34\u5858\uff1a\u4e00\u4e2a\u5728\u5de6\u4e0a\u89d2\uff0c\u4e00\u4e2a\u5728\u5de6\u4e0b\u89d2\uff0c\u8fd8\u6709\u4e00\u4e2a\u6cbf\u7740\u53f3\u4fa7\u3002\u7531\u4e8e\u6700\u8fd1\u7684\u964d\u96e8\uff0c\u6c34\u5728\u519c\u592b\u7ea6\u7ff0\u7684\u7530\u5730\u91cc\u79ef\u805a\u4e86\u3002\u4e2a\u5b57\u7b26\uff0c\u8868\u793a\u519c\u592b\u7ea6\u7ff0\u7530\u5730\u7684\u4e00\u884c\u3002\uff08\u7531 ChatGPT 4o \u7ffb\u8bd1\uff09\u884c\uff1a\u519c\u592b\u7ea6\u7ff0\u7530\u5730\u4e2d\u7684\u6c34\u5858\u6570\u91cf\u3002\u6bcf\u4e2a\u65b9\u683c\u4e2d\u8981\u4e48\u662f\u6c34\uff08\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/52894.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-11T13:14:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250811131419-6899ecabc5aed.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=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/52894.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/52894.html\",\"name\":\"\u6d1b\u8c37 P1596 [USACO10OCT] Lake Counting S-\u666e\u53ca- \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-11T13:14:21+00:00\",\"dateModified\":\"2025-08-11T13:14:21+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/52894.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/52894.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/52894.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u6d1b\u8c37 P1596 [USACO10OCT] Lake Counting S-\u666e\u53ca-\"}]},{\"@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":"\u6d1b\u8c37 P1596 [USACO10OCT] Lake Counting S-\u666e\u53ca- \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\/52894.html","og_locale":"zh_CN","og_type":"article","og_title":"\u6d1b\u8c37 P1596 [USACO10OCT] Lake Counting S-\u666e\u53ca- \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb200\u6b21\u3002\u519c\u592b\u7ea6\u7ff0\u60f3\u8981\u5f04\u6e05\u695a\u4ed6\u7684\u7530\u5730\u91cc\u5f62\u6210\u4e86\u591a\u5c11\u4e2a\u6c34\u5858\u3002\u4e00\u4e2a\u6c34\u5858\u662f\u7531\u8fde\u901a\u7684\u6c34\u65b9\u683c\u7ec4\u6210\u7684\uff0c\u5176\u4e2d\u4e00\u4e2a\u65b9\u683c\u88ab\u8ba4\u4e3a\u4e0e\u5b83\u7684\u516b\u4e2a\u90bb\u5c45\u76f8\u90bb\u3002\u7ed9\u5b9a\u519c\u592b\u7ea6\u7ff0\u7530\u5730\u7684\u793a\u610f\u56fe\uff0c\u786e\u5b9a\u4ed6\u6709\u591a\u5c11\u4e2a\u6c34\u5858\u3002\u601d\u8def\uff1a\u7528 dfs \u641c\u7d22 W \u4ee5\u53ca\u5468\u56f4\u56db\u4e2a\u65b9\u5411\u7684 W\uff0c\u72ec\u7acb\u641c\u7d22\uff08\u5373\u4e0d\u662f\u4ece\u5176\u5b83W\u9012\u5f52\u641c\u7d22\uff09\u6b21\u6570\u5c31\u662f\u6c34\u5858\u6c34\u91cf\u3002\u8f93\u51fa\u8be6\u60c5\uff1a\u5171\u6709\u4e09\u4e2a\u6c34\u5858\uff1a\u4e00\u4e2a\u5728\u5de6\u4e0a\u89d2\uff0c\u4e00\u4e2a\u5728\u5de6\u4e0b\u89d2\uff0c\u8fd8\u6709\u4e00\u4e2a\u6cbf\u7740\u53f3\u4fa7\u3002\u7531\u4e8e\u6700\u8fd1\u7684\u964d\u96e8\uff0c\u6c34\u5728\u519c\u592b\u7ea6\u7ff0\u7684\u7530\u5730\u91cc\u79ef\u805a\u4e86\u3002\u4e2a\u5b57\u7b26\uff0c\u8868\u793a\u519c\u592b\u7ea6\u7ff0\u7530\u5730\u7684\u4e00\u884c\u3002\uff08\u7531 ChatGPT 4o \u7ffb\u8bd1\uff09\u884c\uff1a\u519c\u592b\u7ea6\u7ff0\u7530\u5730\u4e2d\u7684\u6c34\u5858\u6570\u91cf\u3002\u6bcf\u4e2a\u65b9\u683c\u4e2d\u8981\u4e48\u662f\u6c34\uff08","og_url":"https:\/\/www.wsisp.com\/helps\/52894.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-11T13:14:21+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250811131419-6899ecabc5aed.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/52894.html","url":"https:\/\/www.wsisp.com\/helps\/52894.html","name":"\u6d1b\u8c37 P1596 [USACO10OCT] Lake Counting S-\u666e\u53ca- \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-11T13:14:21+00:00","dateModified":"2025-08-11T13:14:21+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/52894.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/52894.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/52894.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u6d1b\u8c37 P1596 [USACO10OCT] Lake Counting S-\u666e\u53ca-"}]},{"@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\/52894","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=52894"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/52894\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/52893"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=52894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=52894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=52894"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=52894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}