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

 #include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdio>
#include <queue>
using namespace std;
const int maxn = ;
char ma[maxn][maxn];
int num[maxn][maxn];
bool inq[maxn*maxn];
int tx[]={ ,-, -, -, , , , ,};
int ty[]={ -,-, , , , , ,- , -};
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)==){
queue<int>Q;
for(int i=; i<n; i++){
scanf("%s",ma[i]);
for(int j=; j<m; j++)
if(ma[i][j]=='.') {
Q.push(i*m+j);
}
}
while(!Q.empty()){
int id = Q.front(); Q.pop();
int xx = id/m, yy=id%m;
for(int i =; i<; i+=){
int sum=,loc=-;
for(int j=i; j<i+; j++){
int dx = xx + tx[j];
int dy = yy + ty[j];
if(dx<||dx>=n ||dy>=m||dy<)
sum=;
if(ma[dx][dy]=='*')
sum++,loc=dx*m+dy;
if(sum>)break;
}
if(sum==){
ma[loc/m][loc%m]='.'; Q.push(loc);
}
}
}
for(int i=; i<n; i++)
printf("%s\n",ma[i]);
}
return ;
}

codeforces D - Arthur and Walls的更多相关文章

  1. CodeForces 525D Arthur and Walls

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

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

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

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

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

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

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

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

  7. [BFS,大水题] Codeforces 198B Jumping on Walls

    题目:http://codeforces.com/problemset/problem/198/B Jumping on Walls time limit per test 2 seconds mem ...

  8. Codeforces 508E Arthur and Brackets 区间dp

    Arthur and Brackets 区间dp, dp[ i ][ j ]表示第 i 个括号到第 j 个括号之间的所有括号能不能形成一个合法方案. 然后dp就完事了. #include<bit ...

  9. Codeforces 101628A - Arthur's Language

    101628A - Arthur's Language 思路:dp,状态转移见代码. 代码: #include<bits/stdc++.h> using namespace std; #d ...

随机推荐

  1. 23种设计模式之责任链模式(Chain of Responsibility)

    责任链模式是一种对象的行为型模式,避免请求发送者与接收者耦合在一起,让多个对象都有可能接收请求,将这些对象连接成一条链,并且沿着这条链传递请求,直到有对象处理它为止.责任链模式不保证每个请求都被接受, ...

  2. 使用COSBench工具对ceph s3接口进行压力测试

    一.COSBench安装 COSBench是Intel团队基于java开发,对云存储的测试工具,全称是Cloud object Storage Bench 吐槽下,貌似这套工具是intel上海团队开发 ...

  3. Android studio was unable to create a local connection in order...

    以管理员身份运行cmd 输入netsh winsock reset 重启电脑

  4. RabbitMQ服务端配置详解(转自:http://www.cnblogs.com/zhen-rh/p/6884297.html)

    RabbitMQ支持三种配置方式: 1) 读取环境变量中配置, 这包括shell中环境变量和rabbitmq-env.conf/rabbitmq-env-conf.bat文件中配置的环境变量 可配置如 ...

  5. HTML5是什么?如何鉴定HTML5产品?[转]

    转自:http://www.jscode.cn/web/v62484 Html 5开始大热标志性的事件是Apple 前CEO Steve Jobs 公开炮轰Flash,并指出Flash在移动终端的不利 ...

  6. 9.20 session

    2018-9-20 13:14:40 Cookie session 参考 :http://www.cnblogs.com/liwenzhou/p/8343243.html 类视图  cbv 注册 ur ...

  7. java.exe和javaw.exe有什么区别

  8. 《机器学习实践》程序清单3-7 plotTree函数

    这个plotTree函数,比较聪明,比较简化,比较抽象,作者一定是逐步优化和简化到这个程度的.我是花了小两天时间,断断续续看明白的,还是在参考了另一篇文章以后.这里是链接http://www.cnbl ...

  9. IP报文

      位字段的值设置为二进制的0100表示IP版本4(IPv4).设置为0110表示IP版本6(IPv6)   位,它表示32位字长的IP报头长度,设计报头长度的原因是数据包可选字段大小会发生变化.IP ...

  10. 【PHP】PHP初学者的学习线路

    先来看下PHP初学者的学习线路: (1) 熟悉HTML/CSS/JS等网页基本元素,完成阶段可自行制作简单的网页,对元素属性相对熟悉. (2) 理解动态语言的概念和运做机制,熟悉基本的PHP语法. ( ...