[POJ 1164] The Castle 位运算加搜索
来源:互联网 发布:ibarn网盘系统源码 编辑:程序博客网 时间:2024/04/28 21:42
题目大意:
给定一张图,求dfs图的最大连通块
代码
#include <cstdio>#include <cstring>#include <iostream>using namespace std;int m,n,mat[1000][1000],vis[1000][1000];int cnt(0),cnt2(0);int Dfs(int x,int y) { if(x<1||y<1||x>m||y>n) return 1; if((mat[x][y]&1)==0&&vis[x][y-1]==0) { vis[x][y-1]=1; Dfs(x,y-1); cnt++; } if((mat[x][y]&2)==0&&vis[x-1][y]==0) { vis[x-1][y]=1; Dfs(x-1,y); cnt++; } if((mat[x][y]&4)==0&&vis[x][y+1]==0) { vis[x][y+1]=1; Dfs(x,y+1); cnt++; } if((mat[x][y]&8)==0&&vis[x+1][y]==0) { vis[x+1][y]=1; Dfs(x+1,y); cnt++; } }int main(){ cin>>m>>n; memset(vis,0,sizeof(0)); for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++) { cin>>mat[i][j]; } } int maxx(0); for(int i=1;i<=m;i++) { for(int j=1;j<=n;j++) { if(vis[i][j]==0) { cnt=0;cnt2++; Dfs(i,j); if(cnt>maxx) maxx=cnt; } } } cout<<cnt2<<endl<<maxx<<endl;}
0 0
- [POJ 1164] The Castle 位运算加搜索
- poj 1164 The Castle 位运算+并查集/搜索
- 【POJ】1164【搜索】【The Castle】
- poj 1164:The Castle
- POJ 1164 The Castle
- POJ 1164:The Castle
- POJ 1164 The Castle
- POJ 1164 The Castle
- POJ 1164 The Castle
- POJ 1164 The Castle
- [POJ]1164 The Castle
- USACO The Castle 位运算 FloodFill
- poj 1164 The Castle (dfs)
- POJ 1164 The Castle 笔记
- poj-1164 The Castle 城堡 DFS计数
- poj 1164.The Castle
- poj 3740 Easy Finding 搜索+位运算
- pku 1164 the castle 深度搜索 解题报告
- hdoj 1040 As Easy As A+B 【归并排序】
- eclipse 修改控制台 编码
- HYSBZ 1036(树链剖分)
- DayDayUP_Linux运维学习_ftp安装使用
- Android 学习之四大组件(二)——service
- [POJ 1164] The Castle 位运算加搜索
- C++中文件的读写
- org.osgi.framework.BundleException: Exception in org.eclipse.core.resources.ResourcesPlugin.start()
- Ubuntu14.04下安装为知笔记
- casperjs中调用本地自定义js文件的方法
- 《Deeply-Learned Feature for Age Estimation》论文阅读笔记
- [c++] LeetCode longest substring without repeating characters问题
- 【Android 学习】四大组件(三)——Content Provider
- Linux正则表达式基础