Codeforces Round #297 (Div. 2) D题. Arthur and Walls(BFS)
来源:互联网 发布:mac开机显示客人用户 编辑:程序博客网 时间:2024/06/05 22:54
题目地址:Arthur and Walls
这题有一个脑洞,对于当前的点(i,j)并且此点为”*”来说,若存在包含它的2*2正方形中除了它自己外,另外三个点都是”.”,那么这个点就必须要变成”.”。由于去掉这个点之后会对周围的8个点造成影响,所以可以用BFS去搜。WA第12组的应该是只考虑了会影响到周围的4个点了。
代码如下:
#include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>using namespace std;#define LL __int64#define pi acos(-1.0)#pragma comment(linker, "/STACK:1024000000")const int mod=1e9+7;const int INF=0x3f3f3f3f;const double eqs=1e-9;const int MAXN=40000+10;char mp[2015][2015];int n, m;int jx[]={0,0,1,-1,1,-1,1,-1};int jy[]={1,-1,0,0,1,-1,-1,1};bool check(int x, int y){ if(x<0||x>n||y<0||y>m) return false; if(mp[x][y]=='.') return true; return false;}bool Judge(int x, int y){ if(mp[x][y]!='*') return false; if(check(x+1,y)&&check(x+1,y+1)&&check(x,y+1)) return true; if(check(x+1,y)&&check(x+1,y-1)&&check(x,y-1)) return true; if(check(x-1,y)&&check(x-1,y+1)&&check(x,y+1)) return true; if(check(x,y-1)&&check(x-1,y-1)&&check(x-1,y)) return true; return false;}queue<pair<int,int> >q;void bfs(){ int i, x, y, a, b; while(!q.empty()){ x=q.front().first;y=q.front().second; q.pop(); if(mp[x][y]=='.') continue ; mp[x][y]='.'; for(i=0;i<8;i++){ a=x+jx[i]; b=y+jy[i]; if(a>=0&&a<n&&b>=0&&b<m&&Judge(a,b)){ q.push(make_pair(a,b)); } } }}int main(){ int i, j; while(scanf("%d%d",&n,&m)!=EOF){ for(i=0;i<n;i++){ scanf("%s",mp[i]); } for(i=0;i<n;i++){ for(j=0;j<m;j++){ if(Judge(i,j)) q.push(make_pair(i,j)); } } bfs(); for(i=0;i<n;i++){ printf("%s\n",mp[i]); } } return 0;}
1 0
- Codeforces Round #297 (Div. 2) D题. Arthur and Walls(BFS)
- Codeforces Round #297 (Div. 2) D. Arthur and Walls
- Codeforces Round #297 (Div. 2) D - Arthur and Walls
- Codeforces Round #297 (Div. 2) D Arthur and Walls
- Codeforces Round #297 (Div. 2) D Arthur and Walls(bfs)
- D. Arthur and Walls(Codeforces Round #297 (Div. 2) 搜索(BFS))
- Codeforces Round #297 (Div. 2)D. Arthur and Walls 搜索bfs
- Codeforces Round #297 (Div. 2) -- D. Arthur and Walls (判断矩形)
- Codeforces Round #297 (Div. 2) 525D Arthur and Walls(dfs)
- Codeforces Round #297 (Div. 2) D - Arthur and Walls (深搜)
- Codeforces Round #297 (Div. 2) D - Arthur and Walls [思维]【思维】
- #297 (div.2) D. Arthur and Walls
- CodeForces 525D D. Arthur and Walls(BFS)
- CodeForces - 525D Arthur and Walls(bfs)
- Codeforces Round #269 (Div. 2) D.MUH and Cube Walls
- Codeforces #297( div2) D. Arthur and Walls ( DFS
- codeforces 525 D Arthur and Walls
- codeforces 525D Arthur and Walls
- [Android]蓝牙bluetooth
- jqgrid 下拉框填充
- 细说 Form (表单)
- matlab之简单粒子群的函数寻优
- 七上八下的生活
- Codeforces Round #297 (Div. 2) D题. Arthur and Walls(BFS)
- windows 7 Oracle 11g安装图解(详细)
- Rand以后每个国家Sample50个记录
- 线段树区间求最大值
- const char *与char *转换的本质
- Java学习笔记_IO
- Ubuntu 14.04 系统托盘图标 无法显示QQ 图标问题,RTX 托盘图标
- 【SICP归纳】6 副作用与环境模型
- URAL 1506. Columns of Numbers(模拟啊 )