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\)的改了没用啊, 而 ...
随机推荐
- HDU 3065 病毒侵袭持续中 (模板题)
病毒侵袭持续中 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- activity标题栏和状态栏操作
修改显示的标题 1.修改AndroidMainfest.xml文件的label标签 2.setTitle("标签"); 去掉标签的显示 1.android:theme=" ...
- 定时执行 Job【转】
Linux 中有 cron 程序定时执行任务,Kubernetes 的 CronJob 提供了类似的功能,可以定时执行 Job.CronJob 配置文件示例如下: ① batch/v2alpha1 是 ...
- 第1节 IMPALA:7、impala的安装以及配置过程
6.制作本地yum源 镜像源是centos当中下载相关软件的地址,我们可以通过制作我们自己的镜像源指定我们去哪里下载impala的rpm包,这里我们使用httpd这个软件来作为服务端,启动httpd的 ...
- 云时代架构阅读笔记十四——我对Hash算法的理解
Hash,一般翻译做“散列”,也有直接音译为“哈希”的,就是把任意长度的输入(又叫做预映射, pre-image),通过散列算法,变换成固定长度的输出,该输出就是散列值.这种转换是一种压缩映射,也就是 ...
- 针对Quartus IP Core的MIF文件格式小记
Quartus里面的ROM IP核进行内容分配,需要在Wizard里面指定.mif文件. 本文有关细节和详细说明,请参照Quartus Prime 帮助文档v15.1 一个常见的mif文件如下所示: ...
- 吴裕雄--天生自然java开发常用类库学习笔记:取得当前日期
import java.util.* ; // 导入需要的工具包 class DateTime{ // 以后直接通过此类就可以取得日期时间 private Calendar calendar = nu ...
- 《ES6标准入门》(阮一峰)--9.数组的扩展
1.扩展运算符 含义 扩展运算符(spread)是三个点(...).它好比 rest 参数的逆运算,将一个数组转为用逗号分隔的参数序列. console.log(...[1, 2, 3]) // 1 ...
- P1081 检查密码
P1081 检查密码 转跳点:
- POJ 3735:Training little cats 联想到矩阵相乘
Training little cats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11208 Accepted: ...