codeforces D - Arthur and Walls
这题说的是给了一个矩阵,必须让.连接起来的图形变成矩形,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的更多相关文章
- CodeForces 525D Arthur and Walls
广搜.看了官方题解才会的..... 定义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 ...
- BFS Codeforces Round #297 (Div. 2) D. Arthur and Walls
题目传送门 /* 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 在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) 525D Arthur and Walls(dfs)
D. Arthur and Walls time limit per test 2 seconds memory limit per test 512 megabytes input standard ...
- Arthur and Walls CodeForces - 525D (bfs)
大意: 给定格点图, 每个'.'的连通块会扩散为矩形, 求最后图案. 一开始想得是直接并查集合并然后差分, 但实际上是不对的, 这个数据就可以hack掉. 3 3 **. .** ... 正解是bfs ...
- [BFS,大水题] Codeforces 198B Jumping on Walls
题目:http://codeforces.com/problemset/problem/198/B Jumping on Walls time limit per test 2 seconds mem ...
- Codeforces 508E Arthur and Brackets 区间dp
Arthur and Brackets 区间dp, dp[ i ][ j ]表示第 i 个括号到第 j 个括号之间的所有括号能不能形成一个合法方案. 然后dp就完事了. #include<bit ...
- Codeforces 101628A - Arthur's Language
101628A - Arthur's Language 思路:dp,状态转移见代码. 代码: #include<bits/stdc++.h> using namespace std; #d ...
随机推荐
- 【CF618G】Combining Slimes 概率+矩阵乘法
[CF618G]Combining Slimes 题意:一个长度为$1\times n$的网格,每次从最右侧往里推入一个数字1或2(数字会一直跑到最左边的空格子里),加入1的概率为p,2的概率为1-p ...
- 神奇的thrust::device_vector与nvcc编译选项
在C++的GPU库thrust中,有两种vector thrust::device_vector<int> D; //GPU使用的内存中的向量 thrust::host_vector< ...
- wordpress---page页面数据调用
在wordpress的开发中,会使用wordpress的的页面,那么页面数据该怎么调用呢? 拿到页面的 content: <?php if(have_posts()) : ?> <? ...
- 8.20 前端 js
2018-8-20 17:40:12 js参考: https://www.cnblogs.com/liwenzhou/p/8004649.html 2018-8-20 20:33:31 css学完了 ...
- vue报错 Uncaught TypeError: Cannot read property ‘children ’ of null
Uncaught TypeError: Cannot read property ‘children ’ of null ratings未渲染完毕,就跳走goods了,取消默认跳转,即可
- hdu 2444 The Accomodation of Students 【二分图匹配】
There are a group of students. Some of them may know each other, while others don't. For example, A ...
- TOP100summit:【分享实录】链家网大数据平台体系构建历程
本篇文章内容来自2016年TOP100summit 链家网大数据部资深研发架构师李小龙的案例分享. 编辑:Cynthia 李小龙:链家网大数据部资深研发架构师,负责大数据工具平台化相关的工作.专注于数 ...
- vs中如何添加库目录、包含目录以及依赖-----转
在生成时,可能需要首先生成某些项目,以便生成由其他项目使用的可执行代码.使用 “解决方案属性页”对话框 ->“通用属性”->“项目依赖项” 设置当前生成顺序.若要访问此对话框,请在“解决方 ...
- grpc protobuf
1.ProtoBuffer是google的一款非常高效的数据传输格式框架 2.一个方法仅能接受一个参数 3.对于定义的message,每个值都有一个唯一的number类型的数字,根据官方文档的解释:它 ...
- Java中子类是否可以继承父类的static变量和方法而呈现多态特性
静态方法 通常,在一个类中定义一个方法为static,那就是说,无需本类的对象即可调用此方法,关于static方法,声明为static的方法有以下几条限制: 它们仅能调用其他的static 方法. 它 ...