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<climits> #include<fstream> using namespace std; ifstream fin("test.in"); ofstream fout("test.out"); const int maxsize = 100000; char map[210][210]; int dx[4] = { -1, 1, 0, 0 }; int dy[4] = { 0, 0, 1, -1 }; int n, m; int ans=1 ; int check(int x, int y) { if (x >= 1 && x <= n&&y >= 1 && y <= m&&map[x][y] != '#') return 1; else return 0; } void bfs(int sx,int sy) { int front = 1,rear = 2,i,j; int qx[maxsize], qy[maxsize]; qx[1] = sx; qy[1] = sy; map[sx][sy] = '#'; while (front <= rear) { int x = qx[front]; int y = qy[front]; for (i = 0; i < 4; i++) { int newx = x + dx[i]; int newy = y + dy[i]; if (check(newx, newy)) { ans++; qx[rear] = newx; qy[rear] = newy; map[newx][newy] = '#'; rear++; } } front++; } } int main(){ int x, y,i,j,sx,sy; fin >>m >> n; while (m&&n){ for (i = 1; i <= n; i++) for (j = 1; j <= m; j++) { fin >> map[i][j]; if (map[i][j] == '@') { sx = i; sy = j; } } bfs(sx, sy); cout << ans << endl; fin >> m >> n; ans = 1; } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator