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\)的改了没用啊, 而 ...
随机推荐
- Python运行目录或压缩文件
如果你在你的工程文件根目录下放一个__main__.py文件,你就可以使用根目录运行整个程序. 你的工程像这样 ex. app/ |-test.py |-test2.py |-__main__.py ...
- Task使用注意
1. CancellationTokenSource的使用 https://binary-studio.com/2015/10/23/task-cancellation-in-c-and-things ...
- Wpa_supplicant 调试故障原因分析
背景 在使用Wpa_supplicant 工具调试Linux的wifi的时候,发现有一些问题.特此记录一下.有些问题是遇到的并已经有了解决方法,一些问题比较发杂,只能作为思路. 问题以及解决办法 1. ...
- selenium 启动、窗口、获取标题
1. from selenium import webdriver #启动chrom浏览器,没写executable_path,这是因为配置环境时,已经将chromdriver放到python安装文件 ...
- iplimage 转HBITMAP
HBITMAP IplImage2hBitmap(IplImage* pImg) { cvFlip(pImg, NULL); BYTE tmp[]; BITMAPINFO *bmi = (BITMAP ...
- STM32F103 USB虚拟串口 驱动例程移植
1)驱动下载及安装.目前ST公司支持WIN7版本号为:VCP_V1.3.1_Setup.exe (在官网上搜索stsw-stm32102即是了):先安装驱动后再插入USB不然安装不成功. 2)固件下载 ...
- Spring MVC RedirectAttributes取值方法
RedirectAttributes是Spring mvc 3.1版本之后出来的一个功能,专门用于重定向之后还能带参数跳转的他有两种带参的方式:第一种: attr.addAttribute(" ...
- Mysql多对多关系的查询
1.创建user表 2.创建gateway表 3.创建user_gateway表 4.创建device表 5.创建gateway_device表 6.创建一个实体类 public class Devi ...
- 使用 Exchange 命令行管理程序查看动态通讯组的成员
本示例返回名为 "全职员工" 的动态通讯组的成员列表. 第一个命令将动态通讯组对象存储在变量$FTE中. 第二个命令使用 Get-Recipient cmdlet 列出与为动态通讯 ...
- 指令——df
df是disk free 的简称,这个指令的功能和作用是查看磁盘空间. 可以加上 -h 的选项,来提高可读性. [he@localhost ~]$ df -h文件系统(磁盘名称) 总容量 ...