标签:
20%的数据,满足 1 <= N,M <= 30 ; 0 <= T <= 0 。
40%的数据,满足 1 <= N,M <= 30 ; 0 <= T <= 2 。
100%的数据,满足 1 <= N,M <= 30 ; 0 <= T <= 30
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<vector> #define MOD 49999 #define INF 100000007 using namespace std; double ans; char s[31][31]; bool v[909]; int dx[5]={0,-1,0,1,0}; int dy[5]={0,0,-1,0,1}; int n,m,t,tot,edge,num[31][31],map[909][909],dis[909],q[50000],next[50000],head[909],list[50000],key[50000]; void insert(int x,int y,int z) { next[++edge]=head[x]; head[x]=edge; list[edge]=y; key[edge]=z; } void build() { int xx,yy; for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) for (int k=1;k<=4;k++) { xx=i+dx[k]; yy=j+dy[k]; if (xx<1||xx>n||yy<1||yy>m) continue; if (s[xx][yy-1]==‘1‘) insert(num[i][j],num[xx][yy],1); else insert(num[i][j],num[xx][yy],0); } } void spfa(int sx,int sy) { for (int i=1;i<=tot;i++) dis[i]=INF; memset(v,0,sizeof(v)); v[num[sx][sy]]=1; dis[num[sx][sy]]=0; int x,t=0,w=1;q[1]=num[sx][sy]; while (t!=w) { t=(t+1)%MOD; x=q[t]; for (int i=head[x];i;i=next[i]) if (dis[x]+key[i]<dis[list[i]]) { dis[list[i]]=dis[x]+key[i]; if (!v[list[i]]) { w=(w+1)%MOD; q[w]=list[i]; v[list[i]]=1; } } v[x]=0; } for (int i=1;i<=tot;i++) map[num[sx][sy]][i]=dis[i]; } double calc(int x,int y) { int x1,x2,y1,y2,sum; x1=(x-1)/m+1; y1=(x-1)%m+1; x2=(y-1)/m+1; y2=(y-1)%m+1; sum=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); return sqrt(double(sum)); } int main() { scanf("%d%d%d",&n,&m,&t); for (int i=1;i<=n;i++) scanf("%s",s[i]); tot=0; edge=0; for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) num[i][j]=++tot; build(); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) spfa(i,j); for (int i=1;i<=tot;i++) for (int j=1;j<=tot;j++) { int x1=(i-1)/m+1,y1=(i-1)%m+1; if (map[i][j]<=t-(s[x1][y1-1]==‘1‘)) { double x=calc(i,j); ans=max(ans,x); } } printf("%.6lf",ans); return 0; }
TYVJ上直接全部输出-0.00000 …… 0msWA……八中A了
标签:
原文地址:http://www.cnblogs.com/ws-fqk/p/4646525.html