1#include <iostream>2#include <cstdio>3#include <cmath>4#include <cstring>5 using namespacestd;6 intn,m,t;7 Doubleans=0;8 BOOLmp[ to][ to],inq[ to][ to],vis[ to][ to];9 intdis[ to][ to];Ten intdx[4]={1,-1,0,0}; One intdy[4]={0,0,-1,1}; A structdata{ - intx, y; -}q[100000]; the voidGetans (intXinty) - { - for(inti=x;i<=n;i++) - for(intj=1; j<=m;j++) +if(dis[i][j]<=t&& (Y-J) * (y-j) + (x-i) * (x-i) >ans) -ans= (Y-J) * (y-j) + (x-i) * (X-i); + } A voidSearchintXxintyy) at { -intnowx,nowy,i,t=1, w=1, Nx,ny; -q[1].x=xx;q[1].y=yy; -memset (INQ,0,sizeof(INQ)); -memset (DIS,127,sizeof(DIS)); -inq[xx][yy]=1;d is[xx][yy]=Mp[xx][yy]; in while(t<=W) - { tonowx=q[t].x;nowy=q[t].y; +t++; - for(i=0;i<4; i++) the { *nx=nowx+dx[i];ny=nowy+Dy[i]; $if(nx>n| | nx<xx| | ny>m| | ny<1)Continue;Panax Notoginseng if(dis[nowx][nowy]+mp[nx][ny]<Dis[nx][ny]) - { thedis[nx][ny]=dis[nowx][nowy]+Mp[nx][ny]; +if(!Inq[nx][ny]) A { theq[++w].x=nx;q[w].y=ny;inq[nx][ny]=1; + } - } $ } $inq[nowx][nowy]=0; - } - Getans (xx,yy); the } - intMain ()Wuyi { thescanf"%d%d%d",&n,&m,&T); -Charstr[ +]; Wu for(intI=1; i<=n;i++) - { Aboutscanf"%s", str); $ for(intj=0; j<m;j++) -mp[i][j+1]=str[j]-'0'; - } - for(intI=1; i<=n;i++) A for(intj=1; j<=m;j++) + {search (i,j);} theprintf"%.6LF", sqrt (ans)); -return 0; $}
A wide search is centered at each point, the minimum number of obstacles that are saved to each point removed, and the enumeration updates the optimal values.
Bzoj 1295: [SCOI2009] the longest distance