poj3620 DFS
来源:互联网 发布:http默认端口号8080 编辑:程序博客网 时间:2024/06/05 16:40
这是第一次用DFS做题,一遍就A了,很开心。
代码如下:
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int flag,pic[102][102],bj[102][102],N,M;
void dfs (int r,int c)
{
if(r<1||r>N||c<1||c>M)
return;
if(bj[r][c]==1||pic[r][c]!=1)
return ;
flag++;
bj[r][c]=1;
for(int dr=-1;dr<=1;dr++)
{
if(dr!=0)
{
dfs(r+dr,c);
dfs(r,c+dr);
}
}
}
int main()
{
std::ios::sync_with_stdio(false);//这是可以避免cin cout 输入输出缓冲,时间过长。
int K,x,y,sum;
while(cin>>N>>M>>K)
{
sum=0;
memset(pic,0,sizeof(pic));
memset(bj,0,sizeof(bj));
for(int i=1;i<=K;i++)
{
cin>>x>>y;
pic[x][y]=1;
}
for(int i=1;i<=N;i++)
for(int j=1;j<=M;j++)
{
flag=0;
if(bj[i][j]==0&&pic[i][j]==1)
{
dfs(i,j);
if(flag>sum)
sum=flag;
}
}
cout<<sum<<endl;
}
return 0;
}
- poj3620 DFS
- DFS poj3620 Avoid The Lakes
- poj3620 avoid the lakes【dfs】
- DFS poj3620(Avoid The Lakes)
- POJ3620
- poj3620
- POJ3620
- POJ3620
- POJ3620
- DFS:POJ3620-Avoid The Lakes(求最基本的联通块)
- poj2386 poj3620
- POJ3620:Avoid The Lakes
- POJ3620 Avoid The Lakes
- Avoid The Lakes--poj3620
- 搜索入门-----POJ3620
- POJ3620 Avoid The Lakes
- 【poj3620】Avoid The Lakes
- Avoid The Lakes<poj3620>
- Python库的安装方法
- 使用可编辑JComboBox的时遇到的一个坑,编辑后如果JCombobox的焦点还在,则获取不到当前的编辑值。
- ZOJ--1010:Area(线段判交问题)
- 西财2018届电商研究生招生简介
- iOS
- poj3620 DFS
- Linux系统下yum命令
- 6.19总结
- ElasticSearch 简单入门
- JAVA JComboBox的监听事件(ActionListener、ItemListener)
- XL2安装MAC Tesseract-OCR详细讲解
- Tesseract+VS2010开发初学
- Unity游戏UI框架(六):日志系统
- 关于指令集和cpu