#include<iostream>                  //用栈进行的解决;
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<stack>
using namespace std; const int maxn = ; int room_map[maxn][maxn];
bool color[maxn][maxn]; int RoomArea;
int maxRoomArea;
int RoomNum; struct room
{
int r, c;
room(int rr, int cc):r(rr),c(cc) {};
}; void bfs(int r,int c)
{
stack<room> stk;
stk.push(room(r, c));
while (!stk.empty())
{
room rm = stk.top();
int x = rm.r;
int y = rm.c;
if (color[x][y])
stk.pop();
else
{
RoomArea++;
color[x][y] = true;
if ((room_map[x][y] & ) == ) stk.push(room(x, y - )); //向西;
if ((room_map[x][y] & ) == ) stk.push(room(x - , y)); // 向北;
if ((room_map[x][y] & ) == ) stk.push(room(x, y + )); //向东;
if ((room_map[x][y] & ) == ) stk.push(room(x + , y)); //向南;
}
}
}
int main()
{
int r, c;
while (~scanf("%d%d", &r, &c))
{
for (int i = ; i <= r; i++)
for (int j = ; j <= c; j++)
scanf("%d", &room_map[i][j]);
memset(color, false, sizeof(color));
maxRoomArea = ;
RoomNum = ;
for (int i = ; i <= r; i++)
for (int j = ; j <= c; j++)
{
if (!color[i][j])
{
RoomNum++;
RoomArea = ;
bfs(i, j);
maxRoomArea = max(maxRoomArea, RoomArea);
}
}
printf("%d\n", RoomNum);
printf("%d\n", maxRoomArea);
}
return ;
}
#include<algorithm>
#include<cstring>
#include<cstdio> //用栈;
using namespace std; const int maxn = ;
int roommap[maxn][maxn]; //城堡地图;
int color[maxn][maxn]; //房间染色; int room_num, room_area ;
int maxroom_aera; void bfs(int x, int y)
{
if (color[x][y]) return ;
room_area++;
color[x][y] = room_num; //给访问过的房间染色; if ((roommap[x][y] & ) == ) bfs(x, y - ); //向西;
if ((roommap[x][y] & ) == ) bfs(x - , y); //向北;
if ((roommap[x][y] & ) == ) bfs(x, y + ); //向东;
if ((roommap[x][y] & ) == ) bfs(x + , y); //向南;
} int main()
{
void bfs(int x, int y);
int row, cross;
while (~scanf("%d%d", &row,&cross))
{
memset(color, , sizeof(color));
maxroom_aera = ;
room_area = ;
room_num = ;
for (int i = ; i <= row; i++)
{
for (int j = ; j <= cross; j++)
{
scanf("%d", &roommap[i][j]);
}
} for (int i = ; i <= row; i++)
{
for (int j = ; j <= cross; j++)
{
if (!color[i][j])
{
room_num++;
room_area = ;
bfs(i, j);
maxroom_aera = max(maxroom_aera, room_area);
}
}
}
printf("%d\n", room_num);
printf("%d\n", maxroom_aera);
}
return ;
}

poj 1164 深度优先搜索模板题的更多相关文章

  1. Sliding Window POJ - 2823 单调队列模板题

    Sliding Window POJ - 2823 单调队列模板题 题意 给出一个数列 并且给出一个数m 问每个连续的m中的最小\最大值是多少,并输出 思路 使用单调队列来写,拿最小值来举例 要求区间 ...

  2. POJ 3009 深度优先搜索

    问题:打冰球.冰球可以往上下左右4个方向走,只有当冰球撞到墙时才会停下来,而墙会消失.当冰球紧贴墙时,不能将冰球往那个方向打.冰球出界就当输,超过10次还没将冰球打到目标位置也当输.求用最小次数将冰球 ...

  3. POJ 3041 匈牙利算法模板题

    一开始预习是百度的算法 然后学习了一下 然后找到了学长的ppt 又学习了一下.. 发现..居然不一样... 找了模板题试了试..百度的不好用 反正就是wa了..果然还是应当跟着学长混.. 图两边的点分 ...

  4. POJ 1985 Cow Marathon (模板题)(树的直径)

    <题目链接> 题目大意: 给定一颗树,求出树的直径. 解题分析:树的直径模板题,以下程序分别用树形DP和两次BFS来求解. 树形DP: #include <cstdio> #i ...

  5. POJ - 3264 线段树模板题 询问区间最大最小值

    这是线段树的一个模板题,给出一串数字,然后询问区间的最大最小值. 这个其实很好办,只需把线段树的节点给出两个权值,一个是区间的最小值,一个是区间的最大值,初始化为负无穷和正无穷,然后通过不断地输入节点 ...

  6. POJ 2823 Sliding Window​ (模板题)【单调队列】

    <题目链接> <转载于>>> > 题目大意: 给你一段序列和一个长为k的窗口,这个窗口从最左边逐渐向右滑,直到滑到最右边,问你,该窗口在滑动的过程中,最大值和 ...

  7. POJ 3348 Cows | 凸包模板题

    题目: 给几个点,用绳子圈出最大的面积养牛,输出最大面积/50 题解: Graham凸包算法的模板题 下面给出做法 1.选出x坐标最小(相同情况y最小)的点作为极点(显然他一定在凸包上) 2.其他点进 ...

  8. POJ 3041 Asteroids(二分图模板题)

    Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N g ...

  9. POJ 1088 滑雪(模板题 DFS+记忆化)

    Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...

随机推荐

  1. 蜕变成蝶~Linux设备驱动之字符设备驱动

    一.linux系统将设备分为3类:字符设备.块设备.网络设备.使用驱动程序: 字符设备:是指只能一个字节一个字节读写的设备,不能随机读取设备内存中的某一数据,读取数据需要按照先后数据.字符设备是面向流 ...

  2. 自动化测试工具Ranorex的录制功能使用

    由于帆软的 Report 包含gui和web端 设计器 web预览 做自动化测试不适合使用 Katalon 发现了Ranorex Ranorex 是一款在Windows操作系统的上运行的GUI自动测试 ...

  3. python从FTP下载文件

    #!/usr/bin/python # -*- coding: utf-8 -*- """ FTP常用操作 """ from ftplib ...

  4. LeetCode - Subarray sum equals k

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  5. C# WinForm窗体控件GroupBox修改边框颜色控件

    C# WinForm窗体控件GroupBox修改边框颜色控件 1.新建组件这里可以自定义一个GroupBox控件起名为GroupBoxEx 2.增加一个BoderColor属性 private Col ...

  6. Dart 语言简易教程系列

    google Fuchsia系统 及 dart语言简介 在 InteIIiJ IDEA 中搭建 Dart 的开发环境 Dart Linux 开发环境搭建 Dart 语言简易教程(一) Dart 语言简 ...

  7. Go 用JSON加载表格数据

    支持热重载reload,但会有一些问题,下面注释有写 package table import ( "runtime/debug" ) //IntArray int类型数组 typ ...

  8. 【C++ 继承与派生/知识梳理】

    为什么引入继承派生 代码重用扩充 软件的复用 层次分类 派生类的语法定义 class 派生类名(1):继承方式(2)   基类名(3){ 派生成员声明:} *(1)一个派生类——>多个基类,多继 ...

  9. ubuntu安装mysql-connector-python

    在安装MySQL-python时遇到报错: sudo pip install MySQL-python Traceback (most recent call last): File "&l ...

  10. vue 项目总结

    第一次参与设计前端项目 项目接近尾声,抽出时间写一下总结 项目用到技术 vue vue-cli (代理配置) element-ui axios router 技术应用思路 vue 组件封装---技术点 ...