Codeforces Round #297 (Div. 2)D. Arthur and Walls 搜索bfs
题目链接:
http://codeforces.com/contest/525/problem/D
题意
给你一个n*m的田地,有一些*的地方是可以移除变成"."的,然后问你移除最少的"*",使的每一个"."的联通块都是矩形
题解:
2*2 的矩形中,如果有一个 '*' 与三个 '.' ,那么这个 '*' 就一定要变成 ‘.' ,然后bfs
代码
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 #define mem(a) memset(a,0,sizeof(a)) 5 #define mp(x,y) make_pair(x,y) 6 const int INF = 0x3f3f3f3f; 7 const ll INFLL = 0x3f3f3f3f3f3f3f3fLL; 8 inline ll read(){ 9 ll x=0,f=1;char ch=getchar(); 10 while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 11 while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 12 return x*f; 13 } 14 // 15 const int maxn = 2e3+10; 16 17 char mp[maxn][maxn]; 18 int dx[8] = {0,0,1,-1,1,1,-1,-1}; 19 int dy[8] = {1,-1,0,0,1,-1,1,-1}; 20 int n,m; 21 22 void check(int x,int y){ 23 int cnt = 0; 24 for(int i=0; i<2; i++) 25 for(int j=0; j<2; j++){ 26 if(mp[x+i][y+j] == '.') 27 cnt++; 28 } 29 if(cnt == 3){ 30 for(int i=0; i<2; i++) 31 for(int j=0; j<2; j++) 32 mp[x+i][y+j] = '.'; 33 for(int i=0; i<8; i++){ 34 int tx=x+dx[i],ty=y+dy[i]; 35 if(tx<1 || tx>n || ty<1 || ty>m) continue; 36 check(tx,ty); 37 } 38 } 39 } 40 41 int main(){ 42 n=read(),m=read(); 43 for(int i=1; i<=n; i++) 44 for(int j=1; j<=m; j++) 45 scanf(" %c",&mp[i][j]); 46 47 for(int i=1; i<=n; i++) 48 for(int j=1; j<=m; j++) 49 check(i,j); 50 51 for(int i=1; i<=n; i++){ 52 for(int j=1; j<=m; j++) 53 printf("%c",mp[i][j]); 54 puts(""); 55 } 56 57 58 return 0; 59 }
转载于:https://www.cnblogs.com/yxg123123/p/6827695.html
Codeforces Round #297 (Div. 2)D. Arthur and Walls 搜索bfs相关推荐
- BFS Codeforces Round #297 (Div. 2) D. Arthur and Walls
题目传送门 1 /* 2 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 3 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 4 在2*2的方格里,若只有一个是'* ...
- Codeforces Round #297 (Div. 2)E. Anya and Cubes 折半搜索
Codeforces Round #297 (Div. 2)E. Anya and Cubes Time Limit: 2 Sec Memory Limit: 512 MB Submit: xxx ...
- Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心
Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec Memory Limit: 256 MB Submit: xxx ...
- 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie
题目传送门 1 /* 2 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 3 题目倒是很长:) 4 */ 5 #include <cstdio> 6 #include <al ...
- Codeforces Round #167 (Div. 1) C. Dima and Horses(BFS+贪心)
题目大意 有 n(1≤n≤3*105) 匹马,每条马都有几个敌人(不超过 3 个),现在要求把这些马分成两部分(允许一部分中没有一条马),使得对于每条马,和它在同一部分中的敌人的数量不超过1个 给出了 ...
- Codeforces Round #336 (Div. 2) D. Zuma 记忆化搜索
D. Zuma 题目连接: http://www.codeforces.com/contest/608/problem/D Description Genos recently installed t ...
- Codeforces Round #406 (Div. 1) A. Berzerk 记忆化搜索
A. Berzerk 题目连接: http://codeforces.com/contest/786/problem/A Description Rick and Morty are playing ...
- Codeforces Round #619 (Div. 2) F. Super Jaber 多源bfs + 思维转换
传送门 文章目录 题意: 思路: 题意: 给你一个矩阵,每个格子都有一个颜色kkk,每秒可以移动到相邻矩阵或者瞬移到同一颜色的任意矩阵.有qqq个询问,每次询问给出两个点,求从一个点到另一个点的最短时 ...
- 【Codeforces Round #548(Div. 2)】Edgy Trees(数学+bfs求连通块)
题目链接 C. Edgy Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
最新文章
- ZooKeeper布式集群安装及使用
- 转,数组遍历的三种方式
- 去除linux 文件中的控制字符,Shell乱码文件中的控制字符处理
- TopOn的两种测试方法
- nginx 反向代理机制解决前端跨域问题
- NLP Prompt范式,两种主要类型:填充文本字符串空白的完形填空(Cloze)prompt,和用于延续字符串前缀的前缀 (Prefix) prompt。
- 如何入门参与数学建模?
- 【天线】【1】一些名词和简单概念的解释
- 读书笔记——《电商产品经理-基于人、货、场、内容的产品设计攻略》
- Metasploit之——基本后渗透命令
- 逆火效应:该对谁负责?
- 程序化交易学习笔记(六、模式、日内交易模型、Tick模型)
- 七夕告白html网页,html5+CSS3+JS七夕告白功能实现详解
- (内含两种方式)Android 在线查看文档world丶xls丶ppt等文件
- Activity毛玻璃背景效果
- Python爬虫_线程池实例——北京新发地菜价
- 不止ChatGPT,谷歌云 AI 方案早已厉兵秣马!
- LeetCode_Stack_331. Verify Preorder Serialization of a Binary Tree 验证二叉树的前序序列化(Java)【栈,字符串处理】
- TB5 AXD 在win7 vista下 启动失败
- Auto.js网盘下载加打包插件