POJ 3051 DFS
题意:判断连通块大小 水题
//By SiriusRen
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m,a[1111][88],xx[]={1,-1,0,0},yy[]={0,0,1,-1},vis[1111][88],ans,temp;
void dfs(int x,int y){
for(int i=0;i<4;i++){
if(!vis[x+xx[i]][y+yy[i]]&&a[x+xx[i]][y+yy[i]]=='*')
temp++,vis[x+xx[i]][y+yy[i]]=1,dfs(x+xx[i],y+yy[i]);
}
}
int main(){
scanf("%d%d",&m,&n);
for(int i=1;i<=n;i++)
for(int j=0;j<=m;j++)
a[i][j]=getchar();
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(!vis[i][j]&&a[i][j]=='*'){
vis[i][j]=1;
temp=1;
dfs(i,j);
ans=max(ans,temp);
}
printf("%d\n",ans);
}
POJ 3051 DFS的更多相关文章
- POJ 1321 DFS
题意:POJ少见的中文题,福利啊. 思路: 一开始也没有思路呃呃呃 . 裸搜,连样例都过不去...参照了网上的题解:一行一行DFS 茅塞顿开啊. #include <cstdio> #in ...
- POJ 1979 dfs和bfs两种解法
fengyun@fengyun-server:~/learn/acm/poj$ cat 1979.cpp #include<cstdio> #include<iostream&g ...
- poj 1190 DFS 不等式放缩进行剪枝
F - (例题)不等式放缩 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submi ...
- poj 1562 dfs
http://poj.org/problem?id=1562 #include<iostream> using namespace std; ,m=,sum=; ][]; ][]={-,, ...
- POJ 1979 DFS
题目链接:http://poj.org/problem?id=1979 #include<cstring> #include<iostream> using namespace ...
- poj 1088 (dfs+记忆化) 滑雪
题目;http://poj.org/problem?id=1088 感觉对深搜还不太熟练,所以练习一下,类似于连连看的那题,注意的是所求的是最大达长度,并不是从最大的或者最小的点出发得到的就是最长的路 ...
- Oil Deposits(poj 1526 DFS入门题)
http://poj.org/problem?id=1562 ...
- POJ 3414 dfs 回溯
题目链接:http://poj.org/problem?id=3414 题意:三个值A, B, C, A和B是两个杯子的容量,问最短操作数使A或者B里的水量是C.有三种操作. 思路:dfs.暴力 很简 ...
- poj 2531(dfs)
题目链接:http://poj.org/problem?id=2531 思路:由于N才20,可以dfs爆搞,枚举所有的情况,复杂度为2^(n). #include<iostream> #i ...
随机推荐
- leetcode 新题型----SQL,shell,system design
leetcode 主要是一个针对北美的coder人群找工作的代码练习网站,我在2015年初次接触这个网站的时候,总共只有200多道题目,是一个类似acm 的a题网站.这些年变化越来越大,主要是因为找工 ...
- Flume 启动
Configuration是Flume项目的入口程序了,当我们输入 bin/flume-ng agent --conf conf --conf-file conf/kafka1.properties ...
- javascript中的那些宽度和高度
window.outerHeight和window.outerWidth 表示整个浏览器窗体的大小,包括任务栏等. IE9及以上 window.innerHeight和window.in ...
- Linux 下易用的光盘镜像管理工具(虚拟光驱软件)转载
作者: Frazer Kline | 2014-11-23 11:07 评论: 4 收藏: 4 分享: 10 磁盘镜像包括了整个磁盘卷的文件或者是全部的存储设备的数据,比如说硬盘,光盘(DVD,C ...
- 监控web服务(http,本地 / 远程监控nginx)
监控 httpd 服务一: #!/bin/bash #描述: 秒级别监控 http 服务 while [ 1 -lt 2 ] do sleep 10 ai=`netstat -ntl | grep & ...
- MAC下搭建appium UI自动化环境
参考资料: http://qa.blog.163.com/blog/static/190147002201510161119832/ http://blog.csdn.net/liuchunming0 ...
- jsp静态引入(<%@ include file=""%>) 乱码问题
在web.xml中的web-app中加入这段话: <jsp-config> <jsp-property-group> <display-name>JSPConfig ...
- struts2登录后返回登录前的页面
在Action中添加 String getUrl() { return ServletActionContext.getRequest().getHeader("referer") ...
- static_cast 与 dynamic_cast
- 剑指Offer面试题27(Java版):二叉搜索树与双向链表
题目:输入一颗二叉搜索树,将该二叉搜索树转换成一个排序的双向链表.要求不能创建新的结点.仅仅能调整树中结点指针的指向. 比方例如以下图中的二叉搜索树.则输出转换之后的排序双向链表为: 在二叉树中,每一 ...