博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3620 Avoid The Lakes
阅读量:4689 次
发布时间:2019-06-09

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

http://poj.org/problem?id=3620

DFS

从任意一个lake出发

重置联通的lake 并且记录 更新ans

1 #include 
2 #include
3 #include
4 using namespace std; 5 6 7 int N,M,K; 8 bool pool[107][107]; 9 int d[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};10 int res = 0;11 int ans = 0;12 bool OK(int x, int y)13 {14 if (x < 0 || x > N || y < 0 || y > M) return false;15 return pool[x][y];16 }17 void dfs(int x, int y)18 {19 res++;20 pool[x][y] = false;21 int nx, ny;22 for (int i = 0; i < 4; i++)23 {24 nx = x+d[i][0];25 ny = y+d[i][1];26 if ( OK(nx, ny) )27 {28 dfs(nx, ny);29 }30 }31 }32 int main()33 {
35 while (cin >> N >> M >> K)36 {37 memset(pool, 0, sizeof(pool));38 for (int i = 0; i < K; i++)39 {40 int r, c;41 scanf("%d%d", &r, &c);42 pool[r][c] = true;43 }44 res = 0;45 ans = 0;46 for (int i = 1; i <= N; i++)47 for (int j = 1; j <= M; j++)48 {49 if (OK(i, j))50 {51 res = 0;52 dfs(i, j);53 }54 ans = max(ans, res);55 }56 cout << ans << endl;57 }58 return 0;59 }

 

转载于:https://www.cnblogs.com/oscar-cnblogs/p/6745480.html

你可能感兴趣的文章
let const var的区别与作用
查看>>
计算出线在屏幕内的最长坐标
查看>>
使用svn——项目的目录布局
查看>>
Linux学习之CentOS(二十五)--Linux磁盘管理:LVM逻辑卷基本概念及LVM的工作原理
查看>>
【bzoj4310/hdu5030-跳蚤】后缀数组
查看>>
深度信任网络的快速学习算法(Hinton的论文)
查看>>
RSA System.Security.Cryptography.CryptographicException
查看>>
s的封装和信息隐蔽
查看>>
excelhttp://www.cnblogs.com/caoyuanzhanlang/p/3591904.html
查看>>
ArrayList和LinkedList和Vector源码分析
查看>>
webservice整合spring cxf
查看>>
再次编译这个应用程序应该不会有问题
查看>>
Ubuntu-tomcat7目录
查看>>
189. Rotate Array
查看>>
asp.net 的三种开发模式
查看>>
Android 交叉编译 IPerf3
查看>>
Android原生Gallery关于图像Orientation的问题
查看>>
[解题报告] 100 - The 3n + 1 problem
查看>>
Entity Framework 学习高级篇1—改善EF代码的方法(上)
查看>>
Mybatis逆向工程配置文件详细介绍(转)
查看>>