广搜。看了官方题解才会的.....

定义2*2的小矩阵,有三个是点,一个是星,这样的小矩阵被称为元素块。

首先把所有元素块压入队列,每次取出对头,检查是否还是元素块,如果是 那么将那个*改为点,否则跳过

改完之后,检查周围8个点是否是元素块,如果有新产生的元素块,那么压入队列。

这样操作完之后就是答案。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std; struct Node
{
int a,b;
Node(int A,int B){a=A,b=B;}
};
queue<Node>Q;
const int N=;
int n, m;
char g[N][N]; bool check(int x, int y)
{
if (g[x][y] == '.' || x < || y < || x >= n || y >= m)return ;
if (g[x][y - ] == '.'&&g[x - ][y - ] == '.'&&g[x - ][y] == '.')return ;
if (g[x - ][y] == '.'&&g[x - ][y + ] == '.'&&g[x][y + ] == '.')return ;
if (g[x][y + ] == '.'&&g[x + ][y + ] == '.'&&g[x + ][y] == '.')return ;
if (g[x][y - ] == '.'&&g[x + ][y - ] == '.'&&g[x + ][y] == '.')return ;
return ;
} void bfs()
{
for(int i=;i<n;i++)
for(int j=;j<m;j++) if(check(i,j)) Q.push(Node(i,j)); while(!Q.empty())
{
Node h=Q.front(); Q.pop();
if(!check(h.a,h.b)) continue;
g[h.a][h.b]='.'; for(int i=-;i<=;i++)
{
for(int j=-;j<=;j++)
{
if(i==&&j==) continue;
if(check(h.a+i,h.b+j)) Q.push(Node(h.a+i,h.b+j));
}
}
}
} int main()
{
while (~scanf("%d%d", &n, &m))
{
for (int i = ; i < n; i++) scanf("%s", g[i]);
bfs();
for(int i=;i<n;i++) printf("%s\n",g[i]);
}
return ;
}

CodeForces 525D Arthur and Walls的更多相关文章

  1. Codeforces Round #297 (Div. 2) 525D Arthur and Walls(dfs)

    D. Arthur and Walls time limit per test 2 seconds memory limit per test 512 megabytes input standard ...

  2. codeforces D - Arthur and Walls

    这题说的是给了一个矩阵,必须让.连接起来的图形变成矩形,2000*2000的矩形,那么我们就可以知道了,只要是存在一个有点的区域应该尽量将他削为矩形,那么将这个图形进行缩放,最后我们知道只要存在一个2 ...

  3. cf 525D.Arthur and Walls

    判断2*2的正方形,是不是3个"."1个"*"然后暴力bfs就好.(这种处理也是挺神奇的2333%%题解) #include<bits/stdc++.h& ...

  4. Codeforces Round #297 (Div. 2) D. Arthur and Walls [ 思维 + bfs ]

    传送门 D. Arthur and Walls time limit per test 2 seconds memory limit per test 512 megabytes input stan ...

  5. Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索

    Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx ...

  6. BFS Codeforces Round #297 (Div. 2) D. Arthur and Walls

    题目传送门 /* 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 在2*2的方格里,若只有一个是'*',那么它一定要 ...

  7. Arthur and Walls CodeForces - 525D (bfs)

    大意: 给定格点图, 每个'.'的连通块会扩散为矩形, 求最后图案. 一开始想得是直接并查集合并然后差分, 但实际上是不对的, 这个数据就可以hack掉. 3 3 **. .** ... 正解是bfs ...

  8. [BFS,大水题] Codeforces 198B Jumping on Walls

    题目:http://codeforces.com/problemset/problem/198/B Jumping on Walls time limit per test 2 seconds mem ...

  9. Codeforces 508E Arthur and Brackets 区间dp

    Arthur and Brackets 区间dp, dp[ i ][ j ]表示第 i 个括号到第 j 个括号之间的所有括号能不能形成一个合法方案. 然后dp就完事了. #include<bit ...

随机推荐

  1. "urllib"库的学习

    在习题—41遇到这个模块/库, 有兴趣的参考下面这个网址: http://blog.sina.com.cn/s/blog_b369b20d0101kb7m.html # coding: utf-8 i ...

  2. UILabel设置富文本格式显示

    实例化方法和使用方法 实例化方法: 使用字符串初始化 - (id)initWithString:(NSString *)str; 例: NSMutableAttributedString *Attri ...

  3. 实验六 多线程编程 1.随便选择两个城市作为预选旅游目标。实现两个独立的线程分别显示10次城市名,每次显示后休眠一段随机时间(1000ms以内),哪个先显示完毕,就决定去哪个城市。分别用Runnable接口和Thread类实现。

    //继承Thread类 package zuoye; //继承Thread类 public class City extends Thread{ private String name; public ...

  4. great C++ socket library

    NETLINK: http://netlinksockets.sourceforge.net/index.html

  5. myeclipse中的类恢复之前的版本方法

    1.右键要恢复的文件,点击如下的选项. 2.界面中出现之前保存的版本,双击要查看的版本,可对比版本之间的不同之处.点击Replace,恢复版本.

  6. Dash:程序员的好帮手

    Dash 关于Dash是什么.有哪些功能以及该怎么使用,我想直接引用咖啡 生活 美女蛇,这位小伙伴整理的很详细,我这里只说一下Dash的破解方法. 破解 破解补丁下载:Dash3.x_Cracked ...

  7. 分析函数 over用法 之row_number() runk_number

    分析函数用于计算基于组的某种聚合值,每个组返回多个行,而聚合函数每个组只返回一个行 表: create table TB_SCORE ( id NUMBER(10), class VARCHAR2(1 ...

  8. VBS脚本代码(手工编写---在windows 7上调用系统对话框,来选择文件)

    '=========================================================================='' VBScript Source File - ...

  9. cPanel下载及安装信息 /usr/local/cpanel/bin/adduser-->realadduser

    cPanel下载及安装信息 2011年03月31日 发布在 编程开发 留下评论   说到cPanel,懂的人都知道玩意得研究研究. ISO安装 http://layer2.cpanel.net/Cen ...

  10. JavaScript高级程序设计:第三章

    基本概念 一.语法: 1.区分大小写: 2.标识符:指变量.函数.属性的名字,或者函数的参数.标识符可以是按照下列格式规则组合起来的一个或多个字符: (1)第一个字符必须是一个字母.下划线(_).或者 ...