博客
关于我
Avoid The Lakes
阅读量:623 次
发布时间:2019-03-13

本文共 1815 字,大约阅读时间需要 6 分钟。

Avoid The Lakes

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 190   Accepted Submission(s) : 106
Problem 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 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.

 
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 53 22 23 12 31 1
 
Sample Output
4
 题解:相当于水池数目那题,只不过这个是找最大的水的个数;
代码:
1 #include
2 #include
3 int N,M,max,step; 4 int map[110][110]; 5 void dfs(int x,int y){ 6     if(!map[x][y]||x<0||x>=N||y<0||y>=M)return; 7     map[x][y]=0;step++; 8     if(step>max)max=step; 9     dfs(x+1,y);dfs(x-1,y);dfs(x,y+1),dfs(x,y-1);10 //    step--;map[x][y]=1;11     return;12 }13 int main(){14     int K,x,y;15     while(~scanf("%d%d%d",&N,&M,&K)){16         memset(map,0,sizeof(map));17         while(K--){18             scanf("%d%d",&x,&y);19             map[x-1][y-1]=1;20         }21         max=step=0;22         for(x=0;x

 

转载地址:http://wehaz.baihongyu.com/

你可能感兴趣的文章
MySQL Error Handling in Stored Procedures---转载
查看>>
MVC 区域功能
查看>>
MySQL FEDERATED 提示
查看>>
mysql generic安装_MySQL 5.6 Generic Binary安装与配置_MySQL
查看>>
Mysql group by
查看>>
MySQL I 有福啦,窗口函数大大提高了取数的效率!
查看>>
mysql id自动增长 初始值 Mysql重置auto_increment初始值
查看>>
MySQL in 太多过慢的 3 种解决方案
查看>>
MySQL InnoDB 三大文件日志,看完秒懂
查看>>
Mysql InnoDB 数据更新导致锁表
查看>>
Mysql Innodb 锁机制
查看>>
MySQL InnoDB中意向锁的作用及原理探
查看>>
MySQL InnoDB事务隔离级别与锁机制深入解析
查看>>
Mysql InnoDB存储引擎 —— 数据页
查看>>
Mysql InnoDB存储引擎中的checkpoint技术
查看>>
Mysql InnoDB存储引擎中缓冲池Buffer Pool、Redo Log、Bin Log、Undo Log、Channge Buffer
查看>>
MySQL InnoDB引擎的锁机制详解
查看>>
Mysql INNODB引擎行锁的3种算法 Record Lock Next-Key Lock Grap Lock
查看>>
mysql InnoDB数据存储引擎 的B+树索引原理
查看>>
mysql innodb通过使用mvcc来实现可重复读
查看>>