DFS之城堡问题
2019-06-01
17:54:51
坚持!!
题目链接:
http://bailian.openjudge.cn/practice/2815
#include <bits/stdc++.h>
using namespace std; int n = , m = ;
int roomNumber = ;
int roomSize = ; //当前房间的面积大小
int maxRoomSize = ;
int room[][];
int color[][]; void dfs(int x, int y); int main()
{ scanf("%d %d", &n, &m);
for (int i = ; i < n; i++)
{
for (int j = ; j < m; j++)
{
scanf("%d", &room[i][j]);
}
} for(int i = ; i < n; i++)
{
for (int j = ; j < m; j++)
{
if(color[i][j] == )
{
roomNumber++;
roomSize = ;
dfs(i, j);
maxRoomSize = max(maxRoomSize, roomSize); }
}
} cout << roomNumber << endl;
cout << maxRoomSize << endl;
return ;
} void dfs(int x, int y)
{
if(color[x][y] != )
{
return;
}
roomSize++;
color[x][y] = roomNumber;
if((room[x][y] & ) == )
dfs(x, y - ); //向西走
if((room[x][y] & ) == )
dfs(x - , y); //向北走
if((room[x][y] & )== )
dfs(x, y + ); //向东走
if((room[x][y] & ) == )
dfs(x + , y); //向南走
}
DFS之城堡问题的更多相关文章
- 深度优先搜索(dfs),城堡问题
题目链接:http://poj.org/problem?id=1164 1.深搜,每个点都访问一次,没有标记的话,就做深搜,同时标记. #include <iostream> #inclu ...
- HDU 1269 迷宫城堡(DFS)
迷宫城堡 Problem Description 为了训练小希的方向感,Gardon建立了一座大城堡,里面有N个房间(N<=10000)和M条通道(M<=100000),每个通道都是单向的 ...
- 百练oj 2815:城堡问题(dfs)
传送门: http://bailian.openjudge.cn/practice/2815 2815:城堡问题 查看 提交 统计 提示 提问 总时间限制: 1000ms 内存限制: 65536kB ...
- POJ 1164 城堡问题【DFS/位运算/种子填充法/染色法】
1 2 3 4 5 6 7 ############################# 1 # | # | # | | # #####---#####---#---#####---# 2 # # | ...
- HDU 1269.迷宫城堡-Tarjan or 双向DFS
迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- 百练2815:城堡问题(DFS)
描述 1 2 3 4 5 6 7 ############################# 1 # | # | # | | # #####---#####---#---#####---# 2 # # ...
- OpenJ_Bailian 2815 城堡问题(DFS)
题目传送门OpenJ_Bailian 2815 描述 1 2 3 4 5 6 7 ############################# 1 # | # | # | | # #####---### ...
- hdu 1269 迷宫城堡 强连通分量
迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- 洛谷P1457 城堡 The Castle
P1457 城堡 The Castle 137通过 279提交 题目提供者该用户不存在 标签USACO 难度提高+/省选- 提交 讨论 题解 最新讨论 暂时没有讨论 题目描述 我们憨厚的USACO ...
随机推荐
- python实现字符串转换整数
实现一个函数,使其能将字符串转换成整数. 首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止. 当我们寻找到的第一个非空字符为正或者负号时,则将该符号与之后面尽可能多的连续 ...
- Linux学习笔记记录(三)
压缩: 例如将/etc 目录压缩为压缩包tar -cjvf /aaa.tar.bz2 /etc tar -czvf /aaa.tar.gz /etc 解压: tar -xjv ...
- 【Codeforces 992B】Nastya Studies Informatics
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 因为gcd(a,b)=x 所以设a = nx b = mx 又有ab/gcd(a,b)=lcm(a,b)=y 则nmx = y 即n(m*x) ...
- [K/3Cloud]进度条控件编程接口
进度条控件编程接口 1.启动进度查询 this.GetControl<ProgressBar>().Start(2) //每2秒查询一次进度 2.汇报进度 在插件中重载 OnQueryP ...
- 在Myeclipse中拷贝一个web项目,但是tomcat文件夹中没有更新,需要进行修改才能更新。
1.在Myeclipse中拷贝一个web项目,但是tocat文件夹中没有更新,需要进行修改才能更新. 2.方法:右键这个工程,然后Properties->MyEclipse->Projec ...
- Self Centos + Windows server 2016
Set up by Derek: 2019-1-25 登陆个人物理机: license 60天Free , 如果过期,就在 VMware ESXI 6.5.0的黑屏界面去reset. https:/ ...
- Linux下汇编语言学习笔记73 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- 最小生成树 C - Building a Space Station
You are a member of the space station engineering team, and are assigned a task in the construction ...
- zoj——1202 Divide and Count
Divide and Count Time Limit: 2 Seconds Memory Limit: 65536 KB Jack has several beautiful diamon ...
- Codeforces 300E(数学)
题意:给定k个数字,求最小的正整数n,使得“n的阶乘”是“这k个数字的阶乘的积”的倍数.1<=k<=1e6,数字ai满足1<=ai<=1e7 分析:如果我们能对着k个数字的阶乘 ...