POJ1111【BFS】
来源:互联网 发布:淘宝 css 显示代码 编辑:程序博客网 时间:2024/06/05 14:06
在搜1011的时候误搜了1111,简单BFS吧,多一个X就是多四个面,每次看看他的四个面有多少个重复的,然后剪掉,最后答案加上就好了;
code:
//#include <bits/stdc++.h>#include<iostream>#include<cstdio>#include<queue>#include<math.h>#include<string.h>#include<algorithm>using namespace std;typedef long long LL;typedef pair<int,int> PII;char ma[25][25];int n,m,sx,sy;struct asd{ int x,y;};bool vis[25][25];int dx[8]={0,0,-1,1,-1,1,1,-1};int dy[8]={-1,1,0,0,-1,1,-1,1};int BFS(){ int ans=0; asd now,nex; memset(vis,0,sizeof(vis)); queue<asd>q; now.x=sx-1; now.y=sy-1; vis[now.x][now.y]=true; q.push(now); while(!q.empty()) { now=q.front();q.pop(); int temp=4; for(int i=0;i<8;i++) { int xx=now.x+dx[i]; int yy=now.y+dy[i]; if(ma[xx][yy]=='.'||xx<0||yy<0||xx>=n||yy>=m) continue; if(i<4&&ma[xx][yy]=='X') temp--; if(vis[xx][yy]) continue; vis[xx][yy]=1; nex.x=xx; nex.y=yy; q.push(nex); }// printf("%d\n",temp); ans+=temp; } return ans;}int main(){ while(~scanf("%d%d%d%d",&n,&m,&sx,&sy)) { if(!n&&!m&&!sx&&!sy) break; for(int i=0;i<n;i++) scanf("%s",ma[i]); printf("%d\n",BFS()); } return 0;}
0 0
- POJ1111【BFS】
- POJ1111
- poj1111
- poj1111
- poj1111
- poj1111
- poj1111
- poj1111
- 神棍节献礼之——POJ1111 Image Perimeters(bfs)
- POJ1111(Maze)
- poj1111-搜索
- Poj1111结题报告
- POJ1111:Image Perimeters(DFS)
- 1poj1111(dfs)
- poj1111 Image Perimeters
- POJ1111 Image Perimeters
- POJ1111 Image Perimeters(dfs)
- 【编程练习】poj1111
- maven配置文件assembly
- 读《卧底经济学(珍藏版)》- 专家是一致对外的
- Android 蓝牙如何使用
- linux小白操作合集
- 蓝桥杯/nyoj 737 合并石子 区间dp+平行四边形优化
- POJ1111【BFS】
- 图像加载框架比较
- HDU1323 Perfection
- 老毛桃一键还原,安全高效 稳定可靠 全面兼容WINDOWS系统。本程序基于Ghost(v11.02)内核,具有良好的安全和稳定性,真正达到快速备份还原;全面支持和兼容32位和64位的Windows等主
- ”交集“选择器和“并集”选择器
- 优先队列的实现(建堆)
- 基础知识——接口和抽象类
- C#winform UDP通信 发送和接收信息
- 线程