{"id":161,"date":"2010-03-19T20:09:00","date_gmt":"2010-03-19T12:09:00","guid":{"rendered":"http:\/\/localhost\/?p=161"},"modified":"2010-03-19T20:09:00","modified_gmt":"2010-03-19T12:09:00","slug":"scoi2009_the_most_long-distance","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/wjmzbmr\/?p=161","title":{"rendered":"[SCOI2009]\u6700\u957f\u8ddd\u79bb"},"content":{"rendered":"\n<p>[SCOI2009]\u6700\u957f\u8ddd\u79bb<\/p>\n<p>Time Limit:10000MS&#160; Memory Limit:165536K<br \/>Total Submit:25 Accepted:16 <br \/>Case Time Limit:1000MS<\/p>\n<p><strong>Description <\/strong><\/p>\n<p>windy\u6709\u4e00\u5757\u77e9\u5f62\u571f\u5730\uff0c\u88ab\u5206\u4e3a N*M \u5757 1*1 \u7684\u5c0f\u683c\u5b50\u3002 <br \/>\u6709\u7684\u683c\u5b50\u542b\u6709\u969c\u788d\u7269\u3002 <br \/>\u5982\u679c\u4ece\u683c\u5b50A\u53ef\u4ee5\u8d70\u5230\u683c\u5b50B\uff0c\u90a3\u4e48\u4e24\u4e2a\u683c\u5b50\u7684\u8ddd\u79bb\u5c31\u4e3a\u4e24\u4e2a\u683c\u5b50\u4e2d\u5fc3\u7684\u6b27\u51e0\u91cc\u5fb7\u8ddd\u79bb\u3002 <br \/>\u5982\u679c\u4ece\u683c\u5b50A\u4e0d\u53ef\u4ee5\u8d70\u5230\u683c\u5b50B\uff0c\u5c31\u6ca1\u6709\u8ddd\u79bb\u3002 <br \/>\u5982\u679c\u683c\u5b50X\u548c\u683c\u5b50Y\u6709\u516c\u5171\u8fb9\uff0c\u5e76\u4e14X\u548cY\u5747\u4e0d\u542b\u6709\u969c\u788d\u7269\uff0c\u5c31\u53ef\u4ee5\u4eceX\u8d70\u5230Y\u3002 <br \/>\u5982\u679cwindy\u53ef\u4ee5\u79fb\u8d70T\u5757\u969c\u788d\u7269\uff0c\u6c42\u6240\u6709\u683c\u5b50\u95f4\u7684\u6700\u5927\u8ddd\u79bb\u3002 <br \/>\u4fdd\u8bc1\u79fb\u8d70T\u5757\u969c\u788d\u7269\u4ee5\u540e\uff0c\u81f3\u5c11\u6709\u4e00\u4e2a\u683c\u5b50\u4e0d\u542b\u6709\u969c\u788d\u7269\u3002 <\/p>\n<p><strong>Input <\/strong><\/p>\n<p> \u8f93\u5165\u6587\u4ef6maxlength.in\u7b2c\u4e00\u884c\u5305\u542b\u4e09\u4e2a\u6574\u6570\uff0cN M T\u3002 <br \/>\u63a5\u4e0b\u6765\u6709N\u884c\uff0c\u6bcf\u884c\u4e00\u4e2a\u957f\u5ea6\u4e3aM\u7684\u5b57\u7b26\u4e32\uff0c&#8217;0&#8217;\u8868\u793a\u7a7a\u683c\u5b50\uff0c&#8217;1&#8217;\u8868\u793a\u8be5\u683c\u5b50\u542b\u6709\u969c\u788d\u7269\u3002 <\/p>\n<p><strong>Output <\/strong><\/p>\n<p> \u8f93\u51fa\u6587\u4ef6maxlength.out\u5305\u542b\u4e00\u4e2a\u6d6e\u70b9\u6570\uff0c\u4fdd\u75596\u4f4d\u5c0f\u6570\u3002 <\/p>\n<p><strong>Sample Input <\/strong><\/p>\n<p>\u3010\u8f93\u5165\u6837\u4f8b\u4e00\u3011<br \/>3 3 0<br \/>001<br \/>001<br \/>110<\/p>\n<p>\u3010\u8f93\u5165\u6837\u4f8b\u4e8c\u3011<br \/>4 3 0<br \/>001<br \/>001<br \/>011<br \/>000<\/p>\n<p>\u3010\u8f93\u5165\u6837\u4f8b\u4e09\u3011<br \/>3 3 1<br \/>001<br \/>001<br \/>001<\/p>\n<p><strong>Sample Output <\/strong><\/p>\n<p>\u3010\u8f93\u51fa\u6837\u4f8b\u4e00\u3011<br \/>1.414214<\/p>\n<p>\u3010\u8f93\u51fa\u6837\u4f8b\u4e8c\u3011<br \/>3.605551<\/p>\n<p>\u3010\u8f93\u51fa\u6837\u4f8b\u4e09\u3011<br \/>2.828427<\/p>\n<p><strong>Hint <\/strong><\/p>\n<p> 20%\u7684\u6570\u636e\uff0c\u6ee1\u8db3 1 &lt;= N,M &lt;= 30 \uff1b 0 &lt;= T &lt;= 0 \u3002 <br \/>40%\u7684\u6570\u636e\uff0c\u6ee1\u8db3 1 &lt;= N,M &lt;= 30 \uff1b 0 &lt;= T &lt;= 2 \u3002 <br \/>100%\u7684\u6570\u636e\uff0c\u6ee1\u8db3 1 &lt;= N,M &lt;= 30 \uff1b 0 &lt;= T &lt;= 30 \u3002<\/p>\n<p><strong>Source <\/strong><\/p>\n<p> Day2<br \/><a href=\"http:\/\/61.187.179.132:8080\/JudgeOnline\/showproblem?problem_id=1295\" target=\"_blank\">61.187.179.132:8080\/JudgeOnline\/showproblem<\/a><br \/>\u6548\u4efftclsm\u795e\u725b\u76f4\u63a5\u8d34\u9898\u76ee\u4e86\u3002\u3002\u611f\u89c9\u7ed9\u6211\u672c\u6765\u5c31\u5f88\u77ed\u7684\u9898\u89e3\u51d1\u4e86\u70b9\u5b57\u56e7\u3002\u3002<br \/>\u8fd9\u9053\u9898\u76ee\u7684\u611f\u89c9\u662fSCOI2009\u6700\u6c34\u7684\uff0c\u679a\u4e3e\u6bcf\u4e2a\u8d77\u70b9\uff0c\u76f4\u63a5BFS\uff0c\u590d\u6742\u5ea6\u662fO(n^2m^2)\u7684\uff0c\u540c\u65f6\u53ef\u4ee5\u89c4\u5b9a\u7ec8\u70b9\u7684\u6a2a\u5750\u6807\u5927\u4e8e\u8d77\u70b9\u3002\u3002\u51cf\u5c11\u4e00\u534a\u641c\u7d22\u91cf\u3002\u3002<br \/>BFS\u7684\u65f6\u5019\u6ce8\u610f\u8fb9\u6743\u53ef\u4ee5\u662f1\u4e5f\u53ef\u4ee5\u662f0\uff0c\u90a3\u4e48\u7528\u4e00\u4e2adeque\u4ee3\u66ffqueue\uff0c\u9047\u52300\u8fb9\u5c31\u653e\u8fdb\u5bf9\u9996\uff0c\u5426\u5219\u653e\u8fdb\u961f\u5c3e\u5c31OK\u4e86\u3002\u3002<br \/>\u6211\u4eceqzc\u795e\u725b\u7684\u4ee3\u7801\u4e2d\u770b\u5230define\u662f\u53ef\u4ee5\u653e\u5728\u51fd\u6570\u4e2d\u7684\uff0c\u800c\u4e14\u53ef\u4ee5\u7528#undef\u7ed9\u53d6\u6d88\u6389\uff0c\u592aorz\u4e86\u3002\u3002<br \/>Code\uff1a<\/p>\n<p>#include&lt;cstdio&gt;<br \/>#include&lt;iostream&gt;<br \/>#include&lt;algorithm&gt;<br \/>#include&lt;string&gt;<br \/>#include&lt;vector&gt;<br \/>#include&lt;cstring&gt;<br \/>#include&lt;deque&gt;<br \/>#include&lt;cmath&gt;<br \/>#define rep(i,n) for(int i=0;i&lt;n;i++)<br \/>#define pb push_back<br \/>#define pf push_front<br \/>using namespace std;<br \/>typedef pair&lt;int,int&gt; ii;<br \/>const int inf=~0U&gt;&gt;1,maxn=30;<br \/>int n,m,T;<br \/>double ans=0;<br \/>bool Map[maxn][maxn];<br \/>const int di[]={1,0,-1,0},dj[]={0,1,0,-1};<br \/>void bfs(int x,int y)<br \/>{<br \/>    static bool vis[maxn][maxn];<br \/>    static int dist[maxn][maxn];<br \/>    memset(vis,0,sizeof(vis));<br \/>    deque&lt;ii&gt; Q;dist[x][y]=Map[x][y];<br \/>    vis[x][y]=true;Q.pb(ii(x,y));<br \/>    #define legal(i,j) (i&gt;=x&amp;&amp;i&lt;n&amp;&amp;j&gt;=0&amp;&amp;j&lt;m&amp;&amp;!vis[i][j])<br \/>    #define A first<br \/>    #define B second<br \/>    double tx,ty;<br \/>    while(Q.size())<br \/>    {<br \/>        ii t=Q.front();int cost=dist[t.A][t.B],xx,yy;Q.pop_front();<br \/>        if(cost&gt;T)break;<br \/>        tx=t.A-x;ty=t.B-y;<br \/>        ans=max(ans,tx*tx+ty*ty);<br \/>        rep(d,4)<br \/>        {<br \/>            xx=t.A+di[d];<br \/>            yy=t.B+dj[d];<br \/>            if(legal(xx,yy))<br \/>            {<br \/>                if(Map[xx][yy])<br \/>                    Q.pb(ii(xx,yy)),dist[xx][yy]=cost+1;<br \/>                else<br \/>                    Q.pf(ii(xx,yy)),dist[xx][yy]=cost;<br \/>                vis[xx][yy]=true;<br \/>            }<br \/>        }<br \/>    }<br \/>    #undef legal<br \/>    #undef A<br \/>    #undef B<br \/>}<br \/>int main()<br \/>{<br \/>    \/\/freopen(&quot;in&quot;,&quot;r&quot;,stdin);<br \/>    cin&gt;&gt;n&gt;&gt;m&gt;&gt;T;char x;<br \/>    rep(i,n)rep(j,m)cin&gt;&gt;x,Map[i][j]=x==&#8217;1&#8242;;<br \/>    rep(i,n)rep(j,m)bfs(i,j);<br \/>    ans=sqrt(ans);<br \/>    printf(&quot;%0.6lf&quot;,ans);<br \/>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[SCOI2009]\u6700\u957f\u8ddd\u79bb Time Limit:10000MS&#160; Memory Limit:165536KTotal Submit:25 Accepted:16 Case Time Limit:1000MS Description windy\u6709\u4e00\u5757\u77e9\u5f62\u571f\u5730\uff0c\u88ab\u5206\u4e3a N*M \u5757 1*1 \u7684\u5c0f\u683c\u5b50\u3002 \u6709\u7684\u683c\u5b50\u542b\u6709\u969c\u788d\u7269\u3002 \u5982\u679c\u4ece\u683c\u5b50A\u53ef\u4ee5\u8d70\u5230\u683c\u5b50B\uff0c\u90a3\u4e48\u4e24\u4e2a\u683c\u5b50\u7684\u8ddd\u79bb\u5c31\u4e3a\u4e24\u4e2a\u683c\u5b50\u4e2d\u5fc3\u7684\u6b27\u51e0\u91cc\u5fb7\u8ddd\u79bb\u3002 \u5982\u679c\u4ece\u683c\u5b50A\u4e0d\u53ef\u4ee5\u8d70\u5230\u683c\u5b50B\uff0c\u5c31\u6ca1\u6709\u8ddd\u79bb\u3002 \u5982\u679c\u683c\u5b50X\u548c\u683c\u5b50Y\u6709\u516c\u5171\u8fb9\uff0c\u5e76\u4e14X\u548cY\u5747\u4e0d\u542b\u6709\u969c\u788d\u7269\uff0c\u5c31\u53ef\u4ee5\u4eceX\u8d70\u5230Y\u3002 \u5982\u679cwindy\u53ef\u4ee5\u79fb\u8d70T\u5757\u969c\u788d\u7269\uff0c\u6c42\u6240\u6709\u683c\u5b50\u95f4\u7684\u6700\u5927\u8ddd\u79bb\u3002 \u4fdd\u8bc1\u79fb\u8d70T\u5757\u969c\u788d\u7269\u4ee5\u540e\uff0c\u81f3\u5c11\u6709\u4e00\u4e2a\u683c\u5b50\u4e0d\u542b\u6709\u969c\u788d\u7269\u3002 Input \u8f93\u5165\u6587\u4ef6maxlength.in\u7b2c\u4e00\u884c\u5305\u542b\u4e09\u4e2a\u6574\u6570\uff0cN M T\u3002 \u63a5\u4e0b\u6765\u6709N\u884c\uff0c\u6bcf\u884c\u4e00\u4e2a\u957f\u5ea6\u4e3aM\u7684\u5b57\u7b26\u4e32\uff0c&#8217;0&#8217;\u8868\u793a\u7a7a\u683c\u5b50\uff0c&#8217;1&#8217;\u8868\u793a\u8be5\u683c\u5b50\u542b\u6709\u969c\u788d\u7269\u3002 Output \u8f93\u51fa\u6587\u4ef6maxlength.out\u5305\u542b\u4e00\u4e2a\u6d6e\u70b9\u6570\uff0c\u4fdd\u75596\u4f4d\u5c0f\u6570\u3002 Sample Input \u3010\u8f93\u5165\u6837\u4f8b\u4e00\u30113 3 0001001110 \u3010\u8f93\u5165\u6837\u4f8b\u4e8c\u30114 3 0001001011000 \u3010\u8f93\u5165\u6837\u4f8b\u4e09\u30113 3 1001001001 Sample Output \u3010\u8f93\u51fa\u6837\u4f8b\u4e00\u30111.414214 \u3010\u8f93\u51fa\u6837\u4f8b\u4e8c\u30113.605551 \u3010\u8f93\u51fa\u6837\u4f8b\u4e09\u30112.828427 Hint 20%\u7684\u6570\u636e\uff0c\u6ee1\u8db3 1 &lt;= N,M &lt;= 30 \uff1b 0 &lt;= [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/161"}],"collection":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=161"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/161\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}