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 ...
随机推荐
- CSS浏览器兼容问题集-第一部分
CSS对浏览器的兼 容性有时让人很头疼,或许当你了解当中的技巧跟原理,就会觉得也不是难事,从网上收集了IE7,6与Fireofx的兼容性处理方法并整理了一下.对于 web2.0的过度,请尽量用xhtm ...
- CSS3 @font-face 指定英文网页字体
@font-face是CSS3中的一个模块,他主要是把自己定义的Web字体嵌入到你的网页中,随着@font-face模块的出现,我们在Web的开发中使用字体不怕只能使用Web安全字体.可能有人要问 ...
- py2exe 生成带图标的单个文件实例
随便拉了个学习时用的测试程序来做的实例,原程序如下: #Filename:for.py count=0 for i in range(1,100,2): count+=i else: print 't ...
- werkzeug源码阅读笔记(二) 上
因为第一部分是关于初始化的部分的,我就没有发布出来~ wsgi.py----第一部分 在分析这个模块之前, 需要了解一下WSGI, 大致了解了之后再继续~ get_current_url()函数 很明 ...
- 深入 char * ,char ** ,char a[ ] ,char *a[] 内核
本文来自CSDN博客:daiyutage的文章 来源网页地址:http://blog.csdn.net/daiyutage/article/details/8604720 本人觉得这是一编很有价值的文 ...
- JS中的的Url传递中文参数乱码,如何获取Url中参数问题
一:Js的Url中传递中文参数乱码问题,重点:encodeURI编码,decodeURI解码: 1.传参页面Javascript代码:<script type=”text/javascript” ...
- Ubuntu14.0.4 64位 ADT 连接手机调试问题
1:使用 lsusb 命令查看USB 设备 y@y:~$ lsusbBus 001 Device 002: ID 8087:8000 Intel Corp. Bus 001 Device 001: I ...
- NOI十连测 第四测 T2
思路:线段树套可持久化treap,可持久化treap我还是第一次听说.. 改题的时候没看数据范围..乱开数组T_T #include<algorithm> #include<cstd ...
- 关于Keil C51中using关键字的使用心得
刚才看到一位很牛的师兄写的一篇日志中提到了Keil C51中using这个关键字的用法,粗心的我本来一直都没有留意它是用来干嘛的(因为我一般看见它都是在中断服务函数的定义开头处,好像没有了它也可以中断 ...
- 开源欣赏wordpress之文章新增页面如何实现。
本地网址http://localhost/wordpress/wp-admin/post-new.php 进而找到post-new.php页面. 进入之后, require_once( dirname ...