Avoid The Lakes
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: NM, 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 ;
}
												

最新文章

  1. javascript数组去重的两个方法
  2. IOS对.Net返回的Base64string解析问题
  3. 开源面向对象数据库 db4o 之旅,第 1 部分: 初识 db4o
  4. Xperf Basics: Recording a Trace (the easy way)(转)
  5. Walkthrough: Creating and Using a Dynamic Link Library (C++)
  6. facebook分块加载,页面优化,BigPipe,简单实例
  7. 性能超越 Redis 的 NoSQL 数据库 SSDB
  8. 《深入了解Android:Wi-Fi、NFC和GPS音量》勘误表
  9. CodeForces 703A Mishka and Game
  10. lfcp——PB使用
  11. 用canvas整个打飞机游戏
  12. php之异常处理
  13. Autopilot Pattern Redis
  14. MySQL基本操作之命令行操作
  15. Netty 零拷贝(三)Netty 对零拷贝的改进
  16. PHP——初学,基础
  17. 【MySQL数据库】一些bug的解决
  18. android 实现微信分享多张图片的功能
  19. Codeforce 633.C Spy Syndrome 2
  20. 毕业 迷茫 继续OR放弃?

热门文章

  1. zepto.1.1.6.js源码中的each方法学习笔记
  2. 启动PL/SQL Developer 报字符编码不一致错误,Database character set
  3. 从客户端(******)中检测到有潜在危险的 Request.Form 值。
  4. Eclipse Juno 配置反编译插件
  5. POI3.10 根据Excel模版导出数据测试
  6. usb开发笔记
  7. 在非MFC的win 32程序里面能够使用CString类
  8. PSPInstance Object | Web Python
  9. js查找和过滤
  10. 产生冠军(set,map,拓扑结构三种方法)