cf 525D.Arthur and Walls
判断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的更多相关文章
- 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 ...
- CodeForces 525D Arthur and Walls
广搜.看了官方题解才会的..... 定义2*2的小矩阵,有三个是点,一个是星,这样的小矩阵被称为元素块. 首先把所有元素块压入队列,每次取出对头,检查是否还是元素块,如果是 那么将那个*改为点,否则跳 ...
- 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 ...
- 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 ...
- BFS Codeforces Round #297 (Div. 2) D. Arthur and Walls
题目传送门 /* 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 在2*2的方格里,若只有一个是'*',那么它一定要 ...
- Arthur and Walls CodeForces - 525D (bfs)
大意: 给定格点图, 每个'.'的连通块会扩散为矩形, 求最后图案. 一开始想得是直接并查集合并然后差分, 但实际上是不对的, 这个数据就可以hack掉. 3 3 **. .** ... 正解是bfs ...
- codeforces D - Arthur and Walls
这题说的是给了一个矩阵,必须让.连接起来的图形变成矩形,2000*2000的矩形,那么我们就可以知道了,只要是存在一个有点的区域应该尽量将他削为矩形,那么将这个图形进行缩放,最后我们知道只要存在一个2 ...
- 【Henu ACM Round#18 F】Arthur and Walls
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 考虑,为什么一个连通块里面的空格没有变成一个矩形? 如果不是形成矩形的话. 肯定是因为某个2x2的单张方形里面. 只有一个角是墙.其 ...
- 题解 [CF525D] Arthur and Walls
题面 解析 首先考虑将一个\('*'\)变成\('.'\)后会形成什么, 显然至少是一个\(2\times 2\)的矩形. 因为\(1\times 1\)和\(1\times 2\)的改了没用啊, 而 ...
随机推荐
- 如何使用Nexus搭建Maven私服
如何使用Nexus搭建Maven私服 听语音 | 浏览:47 | 更新:2016-09-29 10:22 1 2 3 4 5 6 7 分步阅读 一键约师傅 百度师傅最快的到家服务,最优质的电脑清灰! ...
- Java核心API需要掌握的程度
分类: java技术2009-08-29 01:03 213人阅读 评论(0) 收藏 举报 javaapiswingxmlio Java的核心API是非常庞大的,这给开发者来说带来了很大的方便,经常人 ...
- Jquery实现下拉tab切换
//需求:分别点击html,css,js元素时展示对应的列表内容,其他列表内容要自动收起来 //代码如下 <!DOCTYPE html> <html lang="en&qu ...
- Jquery属性操作、添加类
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 题解 loj2065 「SDOI2016」模式字符串
点分治. 考虑经过当前分治中心\(u\)的点对数量. 这种数点对数的问题,有一个套路.我们可以依次考虑\(u\)的每个儿子,看用当前的儿子,能和之前已经考虑过的所有儿子,组成多少点对.这样所有合法的点 ...
- 在Ubuntu下如何压缩一个文件夹
.gz 解压1:gunzip FileName.gz解压2:gzip -d FileName.gz 压缩:gzip FileName .tar.gz 解压:tar zxvf FileName.tar. ...
- NO27 定时任务
linux定时任务的设置 为当前用户创建cron服务 1. 键入 crontab -e 编辑crontab服务文件 例如 文件内容如下: */2 * * * * /bin/sh /home/a ...
- eclipse、idea中自动生成元模型JPA元模型对象
一.eclipse 1.首先准备好两个jar包hibernate-jpa-2.0-api-1.0.1.Final和hibernate-jpamodelgen-4.3.5.Final 2.选中项目右击 ...
- yolov3测试自己的数据
yolov3测试自己的数据 前言 上一篇我已经介绍了利用yolov3预训练权重文件(只包含卷积层)并训练 只需要进行如下编译: ./darknet detector train cfg/voc.dat ...
- 关于cvPyrSegmentation(src, dst, storage, &comp, level, threshold1, threshold2)函数报错的问题解答
先挂上我写的代码: #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <highgui.h> #incl ...