Avoid The Lakes--poj3620
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7023 | Accepted: 3735 |
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 5
3 2
2 2
3 1
2 3
1 1
Sample Output
4 这个题大意是,给出一串坐标,上下左右连着的算一个,求最大的一个里面有几个元素!
主要运用深搜,搜索一次,标记这个点在其周围找到符合的点就进行递归,
这样一块都会被标记,再计算其个数!取最大的个数
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int N,K,M,a,b,cot,best;
int map[][];
int mov[][]={,,,-,,,-,};
bool can(int x,int y)/判断能否符合条件
{
if(x<||x>=N||y<||y>=K||!map[x][y])
return false;
return true;
}
void dfs(int x,int y)//深搜
{
int xx,yy,i;
map[x][y]=;//标记走过
for(i=;i<;i++)
{
xx=x+mov[i][];
yy=y+mov[i][];
if(can(xx,yy))
{
cot++;
dfs(xx,yy);
}
}
}
int main()
{
int i,j;
while(scanf("%d%d%d",&N,&K,&M)!=EOF)
{
memset(map,,sizeof(map));
for(i=;i<M;i++)
{
scanf("%d%d",&a,&b);
map[a-][b-]=;
}
int sum=;
best=;
for(i=;i<N;i++)
for(j=;j<K;j++)
{
cot=;
if(map[i][j])
{
dfs(i,j);
}
best=best>cot?best:cot;//更新最优解
}
printf("%d\n",best);
}
return ;
}
Avoid The Lakes--poj3620的更多相关文章
- [深度优先搜索] 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 ...
- Avoid The Lakes
Avoid The Lakes Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) To ...
- 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 ...
- DFS:POJ3620-Avoid The Lakes(求最基本的联通块)
Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Description Farmer John's farm was flooded i ...
随机推荐
- 我的开源框架之Accordion控件
需求: (1)实现手风琴面板控件,支持静态HTML与JSON方式创建控件 (2)支持远程加载数据 (3)支持面板激活.远程加载事件注册 (4)支持动态添加.删除项目 实现图例 客户代码 <div ...
- android启动activity文本框不获得焦点
在开发中,常常会碰到这种情况,打开一个activity后,第一个文本框自动获得焦点,同时会弹出软键盘输入框,这样很影响用户体验,现在来看解决方法. 我们先来看看为什么会出现上述情况,原因很简单,文本框 ...
- NodeJS和C++的性能比较(转)
原文地址: http://www.web-tinker.com/article/20374.html 前段时间做了个实验,测试了1E9次的空循环在NodeJS和C++中的执行用时.于是我和小伙伴们瞬间 ...
- html简单定位
(1) 两个块水平排列 将两个块都设为浮动即可.注意不能将两个块的position属性设为absolute(绝对定位) #div1{ background-color: red; float:left ...
- 玩转Firefox侧栏
偶然看到煎蛋网的"玩转firefox侧栏",才注意到它. Firefox侧栏有啥不一样? Firefox可以在侧栏中打开网页. 于是,一系列玩法就出来了... 侧栏打开在线应用 G ...
- MySQL用户管理语句001
总的来说mysql的用户管理方法可以分为如下两种: 1.直接对mysql.user 表进行[insert | update | delete] + flush privileges 这种方式主要针对那 ...
- display:table-cell的惊天作用,直接惊呆你!
一 display:table-cell介绍 ... 二 用法 (1)高度不固定元素,垂直居中 ... (2)高度不固定列表元素,登高排列 ... (3)宽度不固定元素,平均分配 ...
- 直接地址跳转C实现
<C缺陷和陷阱>讲过的一种方法: ( *( void (*)() ) 0 )(); //跳转到0地址执行 解析: 1.void (*p_fun)(void); //声明函数指针 2.voi ...
- 找不到Qt5Cored.dll(Release和Debug版连接了不同的库)
Qt5Cored.dll和Qt5Core.dll文件分别用于Qt软件的Debug版和Release版. 通常会有两个Qt5Core.dll文件,分别位于Qti安装目录下的“Qt5.1.0\5.1.0\ ...
- C# GC 垃圾回收
一.托管 .Net所指的托管资源到底是什么意思呢?是相对于所有资源,还是只限于某一方面的资源?很多人对此不是很了解. 其实.Net所指的托管只是针对内存这一个方面,并不是对于所有的元素:因此对于Str ...