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 |
为什么WA 了 求大佬看看#include<iostream> #include<cstdio> #include<algorithm> #include<string> #include<cstring> #include<math.h> #define ll long long using namespace std; const char black = '.',red = '#'; const int MAX = 20+110; char tile[MAX][MAX]; int W,H; int direction[4][2]={{0,1},{0,-1},{-1,0},{1,0}}; int pos[2],cnt; void dfs(int x,int y); int main() { while(scanf("%d %d",&W,&H)!=-1) { memset(tile,0,sizeof(tile)); if(W==0 && H==0) return 0; cnt = 0; fflush(stdin); for(int i = 1;i<=H;i ++) { for(int j = 1;j<=W;j ++) { scanf("%c",&tile[i][j]); if(tile[i][j]=='@') { pos[0] = i; pos[1] = j; } } fflush(stdin); } tile[pos[0]][pos[1]] = black; dfs(pos[0],pos[1]); cout<<cnt<<endl; } } void dfs(int x,int y) { int tx,ty; cnt ++; tile[x][y] = red; for(int i = 0;i<4;i ++) { tx = x+direction[i][0]; ty = y+direction[i][1]; if(tx<=H&&tx>=1&&ty<=W&&ty>=1&&tile[tx][ty]==black) dfs(tx,ty); } return ; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator