判断2*2的正方形,是不是3个"."1个"*"然后暴力bfs就好。(这种处理也是挺神奇的2333%%题解)

 #include<bits/stdc++.h>
#define INF 0x7fffffff
#define LL long long
#define N 100005
#define pill pair<int ,int >
using namespace std;
inline int ra()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
}
const int dir_x[][] = {{,,},{,-,-},{-,-,},{,,}};
const int dir_y[][] = {{,,},{,,},{,-,-},{,-,-}};
char mat[][];
int n,m;
void bfs()
{
queue<pair<int ,int > > q;
for (int i=; i<n; i++)
for (int j=; j<m; j++)
if (mat[i][j]=='.') q.push(make_pair(i,j));
while (!q.empty())
{
pair<int , int > now=q.front(); q.pop();
int x=now.first,y=now.second;
int pos_x,pos_y,cnt;
for (int i=; i<; i++)
{
cnt=;
int ok=;
for (int j=; j<; j++)
{
int xx=x+dir_x[i][j];
int yy=y+dir_y[i][j];
if (xx>= && xx<n && yy>= && yy<m)
{
if (mat[xx][yy]=='*')
{
pos_x=xx; pos_y=yy;
cnt++;
}
}
else {
ok=;
break;
}
}
if (ok && cnt==)
{
mat[pos_x][pos_y]='.';
q.push(make_pair(pos_x,pos_y));
}
}
}
return;
} void print()
{
for (int i=; i<n; i++)
puts(mat[i]);
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=; i<n; i++)
scanf("%s",mat[i]);
bfs();
print();
return ;
}

cf 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 525D Arthur and Walls

    广搜.看了官方题解才会的..... 定义2*2的小矩阵,有三个是点,一个是星,这样的小矩阵被称为元素块. 首先把所有元素块压入队列,每次取出对头,检查是否还是元素块,如果是 那么将那个*改为点,否则跳 ...

  3. 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 ...

  4. 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 ...

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

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

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

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

  7. codeforces D - Arthur and Walls

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

  8. 【Henu ACM Round#18 F】Arthur and Walls

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 考虑,为什么一个连通块里面的空格没有变成一个矩形? 如果不是形成矩形的话. 肯定是因为某个2x2的单张方形里面. 只有一个角是墙.其 ...

  9. 题解 [CF525D] Arthur and Walls

    题面 解析 首先考虑将一个\('*'\)变成\('.'\)后会形成什么, 显然至少是一个\(2\times 2\)的矩形. 因为\(1\times 1\)和\(1\times 2\)的改了没用啊, 而 ...

随机推荐

  1. 「SP1043」GSS1 - Can you answer these queries I

    传送门 Luogu 解题思路 这题就是 GSS3 的一个退化版,不带修改操作的区间最大子段和,没什么好讲的. 细节注意事项 咕咕咕 参考代码 #include <algorithm> #i ...

  2. 【React Native错误集】Android error “Could not get BatchedBridge, make sure your bundle is packaged properly” on start of app

    问题1:Android error “Could not get BatchedBridge, make sure your bundle is packaged properly” on start ...

  3. 099、Java中String类之字符数组与字符串的转换

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  4. springboot中文官方文档

    springboot中文官方文档 https://www.breakyizhan.com/springboot/3028.html spring框架 https://www.breakyizhan.c ...

  5. PCS 7 V9.0 SP1安装过程截图

  6. 8051单片机中访问int中字节的方法

    在使用单片机中,unsigned int 占2个字节,unsigned char 占一个字节.而单片机是实行的字节寻址.16字节的bit寻址实在是不好用, 不好用在不能建数组. 在实际的开发过程中,要 ...

  7. NMEA-0183

    GPGSA( 当前卫星信息)    例:$GPGSA,A,3,01,20,19,13,,,,,,,,,40.4,24.4,32.2*0A    字段0:$GPGSA,语句ID,表明该语句为GPS DO ...

  8. id 和 class的区别

    id 选择器 ID 只能被指定单个元素使用,无法多个元素使用.像你的身份证号,是唯一的,id 选择器以 “#” 来定义.id选择器的优先级高于class选择器的优先级的 # userid { text ...

  9. 配置 git公钥报错:unknown key type -rsa

    配置 git公钥的时候出现:ssh-keygen unknown key type -rsa 一个解决办法是去本地寻找.ssh文件,参考路径(C:\Users\Administrator.ssh),把 ...

  10. 值得一学的C语言

    P1085 不高兴的津津 #include <stdio.h> int main( ) { int a,b; int max=0; int result; for (int i = 0; ...