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 |
终于AC了!第一次AC留念#include <iostream> #include "stdio.h" #define M 105 #define N 105 using namespace std; char map[M][N]; int m, n; int dir[8][2] = {{0,-1},{-1,-1}, {-1,0}, {-1,1}, {0,1}, {1,1}, {1, 0},{1,-1}}; // define DFS function void DFS(char map[M][N],int x, int y) { int newx, newy, i; map[x][y] = '*'; for(i = 0; i < 8; i++) { newx = x + dir[i][0]; newy = y + dir[i][1]; if(map[newx][newy] == '@' && newx >= 0 && newy >= 0 && newx < M && newy < N) { DFS(map, newx, newy); } } } int main() { int cnt; freopen("input.txt","r",stdin); //setbuf(stdout, NULL); scanf("%d%d", &m,&n); while(m&&n) { cnt = 0; for(int i = 0; i < m; i++) { scanf("%s", &map[i]); } for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { if(map[i][j]== '@'){ DFS(map, i, j); cnt ++; } } } printf("%d\n", cnt); scanf("%d%d", &m,&n); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator