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 |
一次性通过,虽然是个大水题,依然很高兴,附代码#include <iostream> using namespace std; static int sum = 0; int m, n; int numOfRoom; int maxNumOfRoom; int data[55][55]; int visited[55][55]; void dfs(int x, int y) { if(x >= 0 && x < m && y >= 0 && y < n && visited[x][y] == 0) { visited[x][y] = 1; if((data[x][y] & 1) == 0) { dfs(x, y - 1); } if((data[x][y] & 2) == 0) { dfs(x - 1, y); } if((data[x][y] & 4) == 0) { dfs(x, y + 1); } if((data[x][y] & 8) == 0) { dfs(x + 1, y); } sum ++; } } int main() { int i = 0; int j = 0; memset(visited, 0, sizeof(visited)); //freopen("input.txt","r",stdin); //setbuf(stdout, NULL); cin>> m >> n; for(i=0;i < m;i++) { for(j=0;j < n;j++) { cin>>data[i][j]; } } numOfRoom = 0; maxNumOfRoom = 0; for(i=0;i < m;i++) { for(j=0;j < n;j++) { sum = 0; if(visited[i][j] == 0) { dfs(i, j); numOfRoom ++; } maxNumOfRoom = max(sum, maxNumOfRoom); } } cout << numOfRoom << endl; cout << maxNumOfRoom << endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator