USACO 2.1 The Castle
2011-05-03 11:20
337 查看
/* ID: jiafeim1 PROG: castle LANG: C++ */ #include <iostream> #include <fstream> #include <algorithm> #include <string> #include <vector> using namespace std; #define maxN(x,y) ((x)>(y)?(x):(y)) #include <queue> int wall[53][53]; int whatSet[53][53]; int top = 0; int squre[2503]; int max_squre = 0; struct point { int x; int y; point(int xi,int yi) { x=xi; y=yi; } }; void bfs(int x,int y) { int s = 0; queue<point> wq; whatSet[x][y] = top; wq.push(point(x,y)); while(!wq.empty()) { ++s; point p = wq.front(); wq.pop(); int row = p.x; int column = p.y; int wal = wall[row][column]; if(!(wal&1) && whatSet[row][column-1] == -1) { wq.push(point(row,column-1)); whatSet[row][column-1] = top; } if(!(wal&2) && whatSet[row-1][column] == -1) { wq.push(point(row-1,column)); whatSet[row-1][column] = top; } if(!(wal&4) && whatSet[row][column+1] == -1) { wq.push(point(row,column+1)); whatSet[row][column+1] = top; } if(!(wal&8) && whatSet[row+1][column] == -1) { wq.push(point(row+1,column)); whatSet[row+1][column] = top; } } squre[top] = s; if(s>max_squre) max_squre = s; ++top; } char ward; int wall_row; int wall_column; int destory_max = 0; int main() { ofstream fout ("castle.out"); ifstream fin ("castle.in"); int m,n; fin>>m>>n; for(int i = 0 ;i!=n;++i) for(int j = 0;j!=m;++j) { fin>>wall[i][j]; whatSet[i][j] = -1; } for(int i = 0;i!=n;++i) for(int j= 0;j!=m;++j) { if(whatSet[i][j] == -1) bfs(i,j); } for(int column = 0 ;column !=m;++column) for(int row = n-1;row >=0;--row) { int wal = wall[row][column]; if(row>=1&&(wal&2)&&(whatSet[row][column]!=whatSet[row-1][column])) { if(squre[whatSet[row][column]]+squre[whatSet[row-1][column]]>destory_max) { destory_max = squre[whatSet[row][column]]+squre[whatSet[row-1][column]]; wall_row = row + 1; wall_column = column + 1; ward = 'N'; } } if(column<m-1&&(wal&4)&&(whatSet[row][column]!=whatSet[row][column+1])) { if(squre[whatSet[row][column]]+squre[whatSet[row][column+1]]>destory_max) { destory_max = squre[whatSet[row][column]]+squre[whatSet[row][column+1]]; wall_row = row + 1; wall_column = column + 1; ward = 'E'; } } } fout<<top<<endl; fout<<max_squre<<endl; fout<<destory_max<<endl; fout<<wall_row<<" "<<wall_column<<" "<<ward<<endl; fin.close(); fout.close(); return 0; }
相关文章推荐
- [题目] Section 2.1 The Castle(USACO)
- USACO 2.1 The Castle
- USACO2.1 城堡The Castle
- 【洛谷1457 [usaco 2.1]城堡 The Castle】【深搜】
- USACO-cha2-sec2.1 The Castle
- USACO Section 2.1 The Castle (POJ 1164) floodfill
- USACO 2.1 The Castle
- USACO 2.1 The Castle(DFS)
- USACO 2.1 The Castle
- USACO 2.1 The Castle
- USACO-Section2.1 The Castle[bfs]
- USACO-Section2.1 The Castle [搜索][深度优先搜索]
- POJ1164 + USACO Section 2.1 The Castle - 简单的DFS...
- USACO-Section2.1 The Castle【深度优先搜索】
- USACO[2.1]The Castle
- USACO 2.1 The Castle
- USACO Section2.1 The Castle 解题报告
- [USACO2.1]城堡 The Castle
- USACO Section 2.1 The Castle
- USACO--2.1The Castle