{"id":188,"date":"2011-08-22T12:33:58","date_gmt":"2011-08-22T04:33:58","guid":{"rendered":"http:\/\/wangkaixuan.tech\/?p=188"},"modified":"2020-06-04T12:34:42","modified_gmt":"2020-06-04T04:34:42","slug":"zoj-1002-fire-net","status":"publish","type":"post","link":"http:\/\/www.wangkaixuan.tech\/?p=188","title":{"rendered":"zoj 1002 Fire Net"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\/*\n\u6df1\u641c\u89e3\u6cd5\n\u603b\u4f53\u601d\u60f3\u662f\u8fd9\u6837\u7684\n\u7528map\u5b58\u653e\u5730\u56fe\n\u5143\u7d20\u503c\u4e3a2\u8868\u793a\u662f\u5899\n1\u8868\u793a\u662f\u7889\u5821\n0\u8868\u793a\u662f\u8857\u9053\n\u4ece\u5de6\u4e0a\u89d2\u7b2c\u4e00\u4e2a\u5f00\u59cb\u626b\u63cf\u4e00\u76f4\u626b\u63cf\u5230\u53f3\u4e0b\u89d2\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\n\u627e\u5230\u53ef\u4ee5\u653e\u7f6e\u7889\u5821\u7684\u5730\u65b9\u7136\u540e\u653e\u7f6e\u7b2c\u4e00\u4e2a\u7889\u5821\n\u6807\u8bb0\u8be5\u4f4d\u7f6e\u4e3a\u7889\u5821\u653e\u7f6e\u4f4d\u7f6e\n\u7136\u540e\u518d\u4ece\u5934\u626b\u63cf\u53ef\u4ee5\u653e\u7f6e\u7889\u5821\u7684\u5730\u65b9\n\u91cd\u590d\u4e0a\u8ff0\u8fc7\u7a0b\u76f4\u5230\u627e\u4e0d\u5230\u53ef\u4ee5\u653e\u7f6e\u7889\u5821\u7684\u4f4d\u7f6e\u7684\u65f6\u5019\u4e3a\u6b62\n\u7528ans\u8bb0\u5f55\u6df1\u641c\u7684\u6700\u5927\u6df1\u5ea6\u5373\u4e3a\u53ef\u4ee5\u653e\u7f6e\u7684\u6700\u5927\u7889\u5821\u6570\u76ee\n*\/\n#define LOCAL\n#include&lt;iostream>\n#include&lt;cstdio>\n#include&lt;cmath>\n#include&lt;cstring>\n#include&lt;cstdlib>\n#include&lt;cctype>\n#include&lt;iomanip>\n#include&lt;string>\n#include&lt;algorithm>\n#include&lt;ctime>\n#include&lt;stack>\n#include&lt;queue>\n#include&lt;vector>\nusing namespace std;\nint n,ans,map&#91;5]&#91;5];\nbool legal(int x,int y)\/\/\u5224\u65ad\u5f53\u524d\u4f4d\u7f6e\u662f\u5426\u53ef\u653e\u7f6e\u7889\u5821\n{\n\tint i;\n\t\/\/\u4f9d\u6b21\u68c0\u7d22\u56db\u4e2a\u65b9\u5411\u5982\u679c\u51fa\u73b0\u4e86\u4e0d\u53ef\u653e\u7f6e\u7684\u60c5\u51b5\u76f4\u63a5\u8fd4\u56de\u5f53\u524d\u4f4d\u7f6e\u4e0d\u53ef\u7528\n\t\/\/\u82e5\u6ca1\u6709\u5219\u5f85\u5b9a\n\tif(map&#91;x]&#91;y]) return false;\n\tif(x>0)\/\/up\n\tfor(i=x-1;i>=1;i--)\n\tif(map&#91;i]&#91;y]==2)\n\t\t\tbreak;\n\telse if(map&#91;i]&#91;y]==1)\n\t\t\treturn false;\n\tif(x&lt;n)\/\/down\n\tfor(i=x+1;i&lt;=n;i++)\n\tif(map&#91;i]&#91;y]==2)\n\t\t\tbreak;\n\telse  if(map&#91;i]&#91;y]==1)\n\t\t\treturn false;\n\tif(y>0)\/\/left\n\tfor(i=y-1;i>=1;i--)\n\t\tif(map&#91;x]&#91;i]==2)\n\t\t\tbreak;\n\t\telse\n\t\tif(map&#91;x]&#91;i]==1)\n\t\t\treturn false;\n\tif(y&lt;n)\/\/right\n\tfor(i=y+1;i&lt;=n;i++)\n\t\tif(map&#91;x]&#91;i]==2)\n\t\t\tbreak;\n\t\telse\n\t\tif(map&#91;x]&#91;i]==1)\n\t\t\treturn false;\n\treturn true;\/\/\u82e5\u68c0\u7d22\u56db\u4e2a\u65b9\u5411\u5747\u6ca1\u6709\u51fa\u73b0\u4e0d\u53ef\u653e\u7f6e\u7684\u60c5\u51b5\n\t\/\/\u5219\u8be5\u4f4d\u7f6e\u80af\u5b9a\u53ef\u4ee5\u653e\u7f6e\u4e00\u4e2a\u7889\u5821\n}\nvoid DFS(int m)\/\/\u7528m\u8bb0\u5f55\u6df1\u641c\u6df1\u5ea6\n{\n\tint i,j;\n\tfor(i=1;i&lt;=n;i++)\/\/\u4ece\u5de6\u4e0a\u89d2\u7b2c\u4e00\u4e2a\u4f4d\u7f6e\u5230\u53f3\u4e0b\u89d2\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u4f9d\u6b21\u8fdb\u884c\u68c0\u7d22\n\t{\n\t\tfor(j=1;j&lt;=n;j++)\n\t\t{\n\t\t\tif(legal(i,j))\/\/\u5982\u679c\u53ef\u653e\u7f6e\u7889\u5821\n\t\t\t{\n\t\t\t\tmap&#91;i]&#91;j]=1;\/\/\u6807\u8bb0\u4e3a\u5df2\u653e\u7f6e\n\t\t\t\tDFS(m+1);\/\/\u8fdb\u5165\u4e0b\u4e00\u5c42\u6df1\u641c\n\t\t\t\tmap&#91;i]&#91;j]=0;\/\/\u8fd4\u56de\u65f6\u53cd\u6807\u8bb0\n\t\t\t}\n\t\t}\n\t}\n\tans=(ans>m?ans:m);\/\/\u8bb0\u5f55\u6700\u5927\u6df1\u641c\u6df1\u5ea6\n}\nint main()\n{\n#ifdef LOCAL\n       freopen(\"input.txt\",\"r\",stdin);\n       freopen(\"output.txt\",\"w\",stdout);\n#endif\n \n\t   int i,j;char ch;\n\t   while(cin>>n&amp;&amp;n)\n\t   {\n\t\t\tmemset(map,0,sizeof(map));\/\/\u521d\u59cb\u5316\u5730\u56fe\n\t\t   for(i=1;i&lt;=n;i++)\n\t\t\t{\n\t\t\t\tfor(j=1;j&lt;=n;j++)\n\t\t\t\t{\n\t\t\t\t\tcin>>ch;\n\t\t\t\t\tif(ch=='X')\/\/\u6807\u8bb0\u5899\u7684\u4f4d\u7f6e\n\t\t\t\t\t\tmap&#91;i]&#91;j]=2;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans=0;\n\t\t    DFS(0);\/\/\u4ece\u6df1\u5ea6\u4e3a0\u5f00\u59cb\u6df1\u641c\n\t\t\tcout&lt;&lt;ans&lt;&lt;endl;\n\t   }\n\t\treturn 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-188","post","type-post","status-publish","format-standard","hentry","category-06-01-acm"],"_links":{"self":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=188"}],"version-history":[{"count":0,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/188\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=188"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}