Avoid The Lakes
Avoid The Lakes
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 190 Accepted Submission(s) : 106
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 exactlyK (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.
* 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
* Line 1: The number of cells that the largest lake contains.
3 2
2 2
3 1
2 3
1 1
#include<stdio.h>
#include<string.h>
int N,M,max,step;
int map[][];
void dfs(int x,int y){
if(!map[x][y]||x<||x>=N||y<||y>=M)return;
map[x][y]=;step++;
if(step>max)max=step;
dfs(x+,y);dfs(x-,y);dfs(x,y+),dfs(x,y-);
// step--;map[x][y]=1;
return;
}
int main(){
int K,x,y;
while(~scanf("%d%d%d",&N,&M,&K)){
memset(map,,sizeof(map));
while(K--){
scanf("%d%d",&x,&y);
map[x-][y-]=;
}
max=step=;
for(x=;x<N;x++){
for(y=;y<M;y++){//printf("%d ",map[x][y]);
if(map[x][y])step=,dfs(x,y);
}//puts("");
}
printf("%d\n",max);
}
return ;
}
Avoid The Lakes的更多相关文章
- [深度优先搜索] POJ 3620 Avoid The Lakes
Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8173 Accepted: 4270 D ...
- poj 3620 Avoid The Lakes【简单dfs】
Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6795 Accepted: 3622 D ...
- POJ 3620 Avoid The Lakes【DFS找联通块】
Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6826 Accepted: 3637 D ...
- poj 3620 Avoid The Lakes(广搜,简单)
题目 找最大的一片湖的面积,4便有1边相连算相连,4角不算. runtime error 有一种可能是 数组开的太小,越界了 #define _CRT_SECURE_NO_WARNINGS #incl ...
- POJ 3620 Avoid The Lakes(dfs算法)
题意:给出一个农田的图,n行m列,再给出k个被淹没的坐标( i , j ).求出其中相连的被淹没的农田的最大范围. 思路:dfs算法 代码: #include<iostream> #inc ...
- POJ 3620 Avoid The Lakes (求连接最长的线)(DFS)
Description Farmer John's farm was flooded in the most recent storm, a fact only aggravated by the i ...
- POJ 3620 Avoid The Lakes
http://poj.org/problem?id=3620 DFS 从任意一个lake出发 重置联通的lake 并且记录 更新ans #include <iostream> #inclu ...
- Avoid The Lakes--poj3620
Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7023 Accepted: 3735 D ...
- DFS:POJ3620-Avoid The Lakes(求最基本的联通块)
Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Description Farmer John's farm was flooded i ...
随机推荐
- linux下java调用.so动态库方法2: JNA
摘自:http://blog.csdn.net/todorovchen/article/details/21319033 另请参见: http://blog.sina.com.cn/s/blog_8c ...
- Android 属性动画(Property Animation) 全然解析 (下)
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38092093 上一篇Android 属性动画(Property Animatio ...
- Android应用程序与SurfaceFlinger服务的连接过程分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/7857163 前文在描述Android应用程序和 ...
- webpack构建具备版本管理能力的项目
webpack是时下十分流行的编译和打包工具,它提供一种可扩展的loader的方式,简单的配置,便可以编译打包各类型的文件,包括js.css.image.font.html,以及各种预编译语言都不在话 ...
- Hacker(四)----查看计算机的IP地址
计算机接入Internet后,Internet就会给该计算机分配一个IP地址,若要查看该IP地址,可以借助度娘(百度,google)来实现.输入"IP地址查询"关键字,即可查看当前 ...
- 修改MySQL默认最大连接数
修改MySQL默认最大连接数 MYSQL数据库安装完成后,默认最大连接数是100,一般流量稍微大一点的论坛或网站这个连接数是远远不够的,增加默认MYSQL连接数的方法有两个: 方法一: 进入MYSQL ...
- 转:说说JSON和JSONP,也许你会豁然开朗,含jQuery用例
说到AJAX就会不可避免的面临两个问题,第一个是AJAX以何种格式来交换数据?第二个是跨域的需求如何解决?这两个问题目前都有不同的解决方案,比如数据可以用自定义字符串或者用XML来描述,跨域可以通过服 ...
- js打印数据类型
console.log({}.toString.call(123))--- [object Number].... [object String] [object Undefined] [object ...
- Hadoop: Start-all.sh 后发现JPS后Namenode没有启动
重新格式化Namenode:hadoop namenode -format 然后启动hadoop:start-all.sh 执行下JPS命令就可以看到NameNode了
- SQL server 2008数据库的备份与还原、分离(转)
SQL server 2008数据库的备份与还原.分离(转) 一.SQL数据库的备份: 1.依次打开 开始菜单 → 程序 → Microsoft SQL Server 2008 → SQL Ser ...