Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求救,。。哪位高手指教!总是wrong !这里的数据都试过,可以通过啊#include<stdio.h> #include<string.h> char b[105][15]; typedef struct { int x; int y; }node; int ok(int n,int m,int i,int j,char b[][15]) { if(i-2>=0) {b[i-2][j]='1';b[i-1][j]='1';} if(i+2<n) {b[i+2][j]='1';b[i+1][j]='1';} if(i-1>=0) {b[i-1][j]='1';} if(i+1<n) b[i+1][j]='1'; if(j-2>=0) {b[i][j-2]='1';b[i][j-1]='1';} if(j+2<m) {b[i][j+2]='1';b[i][j+1]='1';} if(j-1>=0) {b[i][j-1]='1';} if(j+1<m) b[i][j+1]='1'; b[i][j]='1'; return 1; } int dfs(char b[][15],int n,int m,int a,node p[]) { int i,count; count=0; for(i=0;i<a;i++) if(b[p[i].x][p[i].y]!='1') { ok(n,m,p[i].x,p[i].y,b); count++; } return count; } int main() { int n,m,i,j,c,s,q,r; node p[1050]; char a[105][15]; while(EOF!=scanf("%d %d",&n,&m)) { s=0; getchar(); for(i=0;i<n;i++) { scanf("%s",a[i]); getchar(); for(j=0;j<m;j++) if(a[i][j]=='P') { p[s].x=i; p[s].y=j; s++;} } c=0; for(i=0;i<s;i++) {for(j=0;j<n;j++) strcpy(b[j],a[j]); for(q=0;q<i;q++) b[p[q].x][p[q].y]='1'; r=dfs(b,n,m,s,p); if(c<r)c=r; } printf("%d\n" ,c ); } //getchar(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator