POJ3620 Avoid The Lakes
来源:互联网 发布:socket.io java服务端 编辑:程序博客网 时间:2024/05/19 02:00
Avoid The Lakes
Description
Farmer John's farm was flooded in the most recent storm, a fact only aggravated by the information that his cows are deathly afraid of water. His insurance agency will only repay him, however, an amount depending on the size of the largest "lake" on his farm.
The farm is represented as a rectangular grid with N (1 ≤ N ≤ 100) rows and M (1 ≤ M ≤ 100) columns. Each cell in the grid is either dry or submerged, and exactly K (1 ≤ K ≤ N × M) of the cells are submerged. As one would expect, a lake has a central cell to which other cells connect by sharing a long edge (not a corner). Any cell that shares a long edge with the central cell or shares a long edge with any connected cell becomes a connected cell and is part of the lake.
Input
* Line 1: Three space-separated integers: N, M, and K
* Lines 2..K+1: Line i+1 describes one submerged location with two space separated integers that are its row and column: R and C
Output
* Line 1: The number of cells that the largest lake contains.
Sample Input
3 4 53 22 23 12 31 1
Sample Output
4
Source
#include<stdio.h>#include<string.h>int ans[10000];int c[100][100],vis[100][100],n,m,t;int dx[4]={1,0,0,-1};int dy[4]={0,1,-1,0};bool pan(int h,int l){ if(c[h][l]&&!vis[h][l]){vis[h][l]=1;return true;} else return false;}bool find(int &h,int &l){ for(;;){ if(l!=m-1){ l++; if(pan(h,l)){return true; } } else{ h++; if(h==n) return false; l=0; if(pan(h,l)){return true;} } }}int dfs(int h,int l){ int x,y,q=1; for(int i=0;i<4;i++){ x=h+dx[i];y=l+dy[i]; if(x>=0&&x<n&&y>=0&&y<m&&pan(x,y)){q=q+dfs(x,y);} }return q;}int main(){ //freopen("t.txt","r",stdin); int k,i,j,u,v; while(scanf("%d%d%d",&n,&m,&k)!=EOF) { memset(c,0,sizeof(c)); memset(vis,0,sizeof(vis));memset(ans,0,sizeof(ans)); for(i=0;i<k;i++){ scanf("%d%d",&u,&v); c[u-1][v-1]=1; } u=0;v=0;t=0; if(pan(u,v)){ans[t]=dfs(u,v);for(;;)if(find(u,v)){ t++;ans[t]=dfs(u,v);}else break;} else {for(;;)if(find(u,v)){t++;ans[t]=dfs(u,v);}else break;}int maxn=-1;for(i=0;i<=t;i++)if(maxn<ans[i])maxn=ans[i];printf("%d\n",maxn); } return 0;}
- POJ3620:Avoid The Lakes
- POJ3620 Avoid The Lakes
- Avoid The Lakes--poj3620
- POJ3620 Avoid The Lakes
- 【poj3620】Avoid The Lakes
- Avoid The Lakes<poj3620>
- Avoid The Lakes(poj3620)
- DFS poj3620 Avoid The Lakes
- poj3620 avoid the lakes【dfs】
- DFS poj3620(Avoid The Lakes)
- DFS:POJ3620-Avoid The Lakes(求最基本的联通块)
- pku3620 Avoid The Lakes
- 1543 Avoid The Lakes
- F. Avoid The Lakes
- Avoid The Lakes
- BNU Avoid The Lakes
- Avoid The Lakes POJ
- Avoid The Lakes
- httpmodule通过httpfilter获取返回的网页内容
- hdu1878 欧拉回路(并查集)
- android 模拟按键
- android activity task 进程,线程综述
- linux echo 怎样输出转义字符?
- POJ3620 Avoid The Lakes
- 做事效率太低?你必须改掉这7种坏习惯
- C# 枚举进程模块
- java中PropertyDescriptor的使用简介
- C++ - "No source available for "__chkstk_ms() at 0x401f0b"" 异常
- OC中的数组:NSArray
- UVa 1398 Meteor 解题报告(扫描线)
- 双系统重装Win7后,Ubuntu 无法启动的解决办法
- C - Fractal(3.4.1)