大意: 给定格点图, 每个'.'的连通块会扩散为矩形, 求最后图案.

一开始想得是直接并查集合并然后差分, 但实际上是不对的, 这个数据就可以hack掉.

3 3

**.

.**

...

正解是bfs, 一个点被扩散当且仅当它所在的某个2*2块中只有它为'*'.

#include <iostream>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head #ifdef ONLINE_JUDGE
const int N = 1e6+10;
#else
const int N = 111;
#endif int n, m;
char s[N][N];
int dx[]={-1,-1,-1,0,1,1,1,0};
int dy[]={-1,0,1,1,1,0,-1,-1};
queue<pii> q;
int chk(int x, int y) {
if (x<1||x>n||y<1||y>m||s[x][y]=='.') return 0;
if (s[x-1][y]=='.'&&s[x-1][y-1]=='.'&&s[x][y-1]=='.') return 1;
if (s[x-1][y]=='.'&&s[x-1][y+1]=='.'&&s[x][y+1]=='.') return 1;
if (s[x][y-1]=='.'&&s[x+1][y-1]=='.'&&s[x+1][y]=='.') return 1;
if (s[x][y+1]=='.'&&s[x+1][y]=='.'&&s[x+1][y+1]=='.') return 1;
return 0;
} int main() {
scanf("%d%d", &n, &m);
REP(i,1,n) scanf("%s", s[i]+1);
REP(i,1,n) REP(j,1,m) if (chk(i,j)) q.push(pii(i,j));
while (q.size()) {
auto t = q.front(); q.pop();
if (!chk(t.x,t.y)) continue;
s[t.x][t.y] = '.';
REP(i,0,7) {
int x=t.x+dx[i],y=t.y+dy[i];
if (chk(x,y)) q.push(pii(x,y));
}
}
REP(i,1,n) puts(s[i]+1);
}

Arthur and Walls CodeForces - 525D (bfs)的更多相关文章

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

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

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

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

  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. Jumping on Walls CodeForces - 198B

    Jumping on Walls CodeForces - 198B 应该是一个隐式图的bfs,或者叫dp. 先是一个TLE的O(nklogn) #include<cstdio> #inc ...

  6. Arthur and Table CodeForces - 557C

    Arthur and Table CodeForces - 557C 首先,按长度排序. 长度为p的桌腿有a[p]个. 要使得长度为p的桌腿为最长,那么要按照代价从小到大砍掉sum{长度不到p的腿的数 ...

  7. CodeForces 525D Arthur and Walls

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

  8. codeforces D - Arthur and Walls

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

  9. cf 525D.Arthur and Walls

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

随机推荐

  1. js前后五年的时间日期万年历

    <script src='bootstrap/js/jquery-1.11.2.min.js'></script>//引入JQUERY文件<div> <sel ...

  2. vue进阶--外卖商家页

    一.准备工作 1.vue特性:轻量级.简洁.高效.组件化.数据驱动 2.技术分析:使用vue- resource与后端交互(ajax通信,ie9+)  使用vue-router作为前端路由   bet ...

  3. 创建 Visual Studio 2017 离线安装

    代码示例: vs_Enterprise.exe --layout E:\VS2017LAYOUT --add Microsoft.VisualStudio.Workload.NetCoreTools ...

  4. Raize 重新编译

    最近项目用到了Raize5的日历控件, 需要在中文版本与英文版本中切换显示, 这个需要修改 RzPopups.pas, 修改了需要重新编译. 费老大劲了.   首选修改 RzBorder.pas, 不 ...

  5. ARM Mcp2515添加驱动

    Mcp2515添加驱动   2012-01-10 21:39:32 上图1: 上图2: 上图3: 之前完成了spi接口驱动,所以mcp2515也是通过spi来读写数据的.就是多加一个中断脚. 另外在2 ...

  6. drf 单表

    ^_^ # [{title,price},{}] 构造的数据结构 简单的FBV/CBV def showbooks(request): # FBV if request.method =='GET': ...

  7. kubernetes pod infra container网络原理

    刚开始接触kubernetes时,对kubelet的--pod-infra-container-image参数非常不能理解,不理解为什么我的业务应用需要依赖一个第三方的容器: 上文入门级kuberne ...

  8. linux使用vim打开乱码问题

    在windows中编辑好的汉字文本文档,上传到Linux下打开乱码. [root@localhost ~]# rpm -ivh /mnt/Packages/lrzsz-0.12.20-36.el7.x ...

  9. MariaDB xtrabackup物理备份与还原

    xtrabackup物理备份 1.1 安装xtraback 安装依赖: [root@localhost ~]# yum install -y perl-DBD-MySQL perl-DBI perl- ...

  10. js 对url进行某个参数的删除,并返回url

    两种情况 1对当前页面的url进行操作 function funcUrlDel(name){ var loca = window.location; var baseUrl = loca.origin ...