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 ...
随机推荐
- dirname的用法:获取文件的父级目录路径
命令:dirname 获取文件的路径(到父级目录)用法:dirname file_name [root@bogon opt]# a=$(dirname /mnt/a/b/c/d/a.sh) [root ...
- windows网卡共享网络时,报Internet连接共享访问被启用时,出现了一个错误。(null)
今天笔者在自己电脑上作试验时,准备将无线网络连接共享给VMnet1时报Internet连接共享访问被启用时,出现了一个错误.(null)错误: 经上网查询到问题原因:没有启用 Windows Fire ...
- 【CF840C】On the Bench DP
[CF840C]On the Bench 题意:给你一个长度为n的数组{ai},定义一个1到n的排列是合法的,当且仅当对于$1\le i <n$,$a_i\times a_{i+1}$不是完全平 ...
- python中的null值
在一个没有接口文档的自动化测试中,只能通过抓包及查日志查看发送的信息,其中有一个接口发送的信息如下: enable_snapshot": true, "new_size" ...
- Unity3D Mecanim :Body Mask的使用、 角色Retargeting原理分析、Apply RootMotion
一.Body Mask的使用 1.1.配置好骨骼后通过Muscles来微调角色骨骼中的运动范围,以避免角色在动画中的不正确的叠加或失真等现象. 1.2.身体遮罩BodyMask更形象的描述就是身体的开 ...
- SOA架构商城一
SOA架构: SOA是Service-Oriented Architecture的首字母简称,它是一种支持面向服务的架构样式.从服务.基于服务开发和服务的结果来看,面向服务是一种思考方式.其实SOA架 ...
- 兵器簿之cocoaPods的安装和使用
以前添加第三方库的时候总是直接去Github下载然后引入,但是如果这些第三方库发生了更新,我们还需要手动去更新项目,所以现在引入之前一直想弄都一直没有弄的cocoaPods,现在演示一把过程 其实非常 ...
- POJ--1050--To the Max(线性动规,最大子矩阵和)
To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44723 Accepted: 23679 Descript ...
- MyBatis学习(一)一个简单的例子
mybatis入门例子 开发步骤: 1.创建java工程 2.加入jar包(依赖包.驱动包) 3.创建sqlMapConfig.xml 4.创建数据库,数据库表USER_C,插入测试记录 5.创建PO ...
- 0002python中dict和list的特殊构造
>>> myinfor = {"name":"qiwsir","site":"qiwsir.github.io& ...