深搜 城堡
来源:互联网 发布:阿里云数据同步 编辑:程序博客网 时间:2024/06/10 20:14
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <stack>using namespace std;int R,C;int rooms[60][60];int color[60][60];int maxRoom=0,roomNum=0;int roomArea;void dfs(int i,int k){ if(color[i][k]) return ; ++roomArea; color[i][k]=roomNum; if(rooms[i][k]&1==0) dfs(i,k-1); if(rooms[i][k]&2==0) dfs(i-1,k); if(rooms[i][k]&4==0) dfs(i,k+1); if(rooms[i][k]&8==0) dfs(i+1,k);}int main(){ int i,j; cin>>R>>C; for(i=0; i<R; i++) for(j=0; j<C; j++) cin>>rooms[i][j]; memset(color,0,sizeof(color)); for(i=0; i<R; i++) for(j=0; j<C; j++) { if(!color[i][j]) { ++roomNum; roomArea=0; dfs(i,j); maxRoom=max(roomArea,maxRoom); } } cout<<roomNum<<endl; cout<<maxRoom<<endl;}
在coursera上看了视频,后悔没让前男友教我深搜
0 0
- 深搜 城堡
- 城堡
- 城堡
- 城堡
- 迷宫城堡(vector+深搜 )
- 【洛谷1457 [usaco 2.1]城堡 The Castle】【深搜】
- 多云城堡
- 积木城堡
- 城堡问题
- 飞行城堡
- 迷宫城堡
- 城堡问题
- 芒卡斯特城堡
- 积木城堡
- 积木城堡
- 城堡问题
- 城堡问题
- 城堡问题
- IO
- ORACLE数据库---多表链接查询
- Observer观察者模式
- 《大话数据结构》读书笔记
- 关于获取chromium最新源代码的几点疑惑
- 深搜 城堡
- 浅析Java匿名内部类在Android事件响应中的应用
- LeetCode 225. Implement Stack using Queues
- iOS模拟器中修改textField键盘类型为中文输入和键盘弹出方法
- ORACLE数据库---子查询
- 复制的虚拟机 ,找不到网卡eth0了,可能会有其他网卡生效,设置eth0生效
- 接收广播BroadcastReceiver
- java程序中修改properties原始文件
- Eclipse中使用maven构建SpringMVC