Codeforces Round #297 (Div. 2)D. Arthur and Walls 搜索bfs

开发者福利!热门AI工具限时免费用 购周边即赠Coding Plan Lite,Claude Code、Cursor等20+工具畅享,效率翻倍! 阅读详情

题目链接:

http://codeforces.com/contest/525/problem/D

题意

给你一个n*m的田地,有一些*的地方是可以移除变成"."的,然后问你移除最少的"*",使的每一个"."的联通块都是矩形

题解:

2*2 的矩形中,如果有一个 '*' 与三个 '.' ,那么这个 '*' 就一定要变成 ‘.' ,然后bfs

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define mp(x,y) make_pair(x,y)
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 2e3+10;

char mp[maxn][maxn];
int dx[8] = {0,0,1,-1,1,1,-1,-1};
int dy[8] = {1,-1,0,0,1,-1,1,-1};
int n,m;

void check(int x,int y){
    int cnt = 0;
    for(int i=0; i<2; i++)
        for(int j=0; j<2; j++){
            if(mp[x+i][y+j] == '.')
                cnt++;
        }
    if(cnt == 3){
        for(int i=0; i<2; i++)
            for(int j=0; j<2; j++)
                mp[x+i][y+j] = '.';
        for(int i=0; i<8; i++){
            int tx=x+dx[i],ty=y+dy[i];
            if(tx<1 || tx>n || ty<1 || ty>m) continue;
            check(tx,ty);
        }
    }
}

int main(){
    n=read(),m=read();
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            scanf(" %c",&mp[i][j]); 

    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            check(i,j);

    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++)
            printf("%c",mp[i][j]);
        puts("");
    }


    return 0;
}
Alphafold2/multimer Conda环境配置与GPU加速优化指南 本文详细介绍了如何在本地服务器或工作站上,通过Conda环境配置并优化GPU加速来部署Alphafold2及其多聚体版本Alphafold2-multimer。内容涵盖从硬件准备、依赖安装、数据库部署到实战预测与常见报错处理的全流程,重点解决了本地安装过程中的依赖冲突与GPU调用失败等关键问题,帮助研究人员高效运行这一蛋白质结构预测工具。 阅读详情

相关推荐

电阻的基本原理、参数、应用与选型

电阻的基本原理、电阻的分类、参数,应用与选型,0欧姆电阻的介绍等。

luobeihai的博客 1万+

Codeforces Round #297 (Div. 2) 纪念第一次Div2 AK

// 虽然是virtual participant但还是爽到、A Vitaliy and Pie题目链接:点击打开链接思路:水题AC代码:#include &lt;iostream&gt; #include &lt;iomanip&gt; #include &lt;algorithm&gt; #include &lt;cstring&gt; #include &lt;cstdio&gt; #inc...

LFhase‘s Blog 505

【DAY11】超参数调整专题1

核心优势: 它不是随机选择下一个点,而是根据先前评估的结果建立一个概率模型(通常是高斯过程),预测哪些参数组合可能产生更好的结果,并据此选择下一个评估点。这使得它在寻找最优解方面通常比随机搜索更高效(用更少的迭代次数达到相似或更好的性能),特别是当模型训练(单次评估)非常耗时的时候。实际上,有着非常多的方式可以实现贝叶斯优化,上面的代码比较简洁美观,贝叶斯优化和网格搜索的代码书写风格高度一致。- 需要定义参数的搜索空间,与随机搜索类似,当搜索空间非常大时,它通常比网格搜索和随机搜索更有效。

daomingwu1的博客 732

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

题目地址:Arthur and Walls 这题有一个脑洞,对于当前的点(i,j)并且此点为”*”来说,若存在包含它的2*2正方形中除了它自己外,另外三个点都是”.”,那么这个点就必须要变成”.”。由于去掉这个点之后会对周围的8个点造成影响,所以可以用BFS去搜。WA第12组的应该是只考虑了会影响到周围的4个点了。 代码如下:#include <iostream> #include <strin

scf0920 1449

D. Arthur and WallsCodeforces Round #297 (Div. 2) 搜索BFS))

D. Arthur and Walls time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Finally it is a day when Arthur has eno

叶孤心的专栏 624

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  Solved: 2xx 题目连接 http://codeforces.com/contest/525/problem/D Description Finall...

weixin_34138377的博客 113

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

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

weixin_33712881的博客 130

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

对图广搜,当当前点的一个脚中的通路大于2个,就把他全染成通路,新的通路加入队列。。 #include #include #include #include #include #include #include #include #include #include #include #include #include #define maxn 2005 #define m

yysys 467

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

D. Arthur and Walls time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Finally it is a day when Arthur has eno

左眼皮跳跳 787

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 standard input output standard output Finally it is a day when Arthur has enough...

weixin_33779515的博客 116

紫书搜索 习题7-8 UVA - 12107 Digit Puzzle IDA*迭代加深搜索

题目链接:https://vjudge.net/problem/UVA-12107题意:给出一个数字谜,要求修改尽量少的数,使修改后的数字谜只有唯一解。空格和数字可以随意替换,但不能增删,数字谜中所有涉及的数必须是没有前导零的正数。输入数字谜一定形如a*b=c,其中a、b、c分别最多有22、4位。题解:http://www.cnblogs.com/tyty-Somnuspoppy/p/636672

yxg_123的博客 953

BZOJ 1024: [SCOI2009]生日快乐 dfs

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1024题意:题解:http://www.cnblogs.com/ljh2000-jump/p/6063364.html 直接搜索每次横着切还是竖着切,同时均分成多少块。因为每个人的面积相等,所以注意一下,切成两半后必须要保证两边分成的块数之比要等于面积之比,仔细想想就可以想通了因为对于当前长

yxg_123的博客 802

洛谷1281 书的复制 二分

题目链接:https://www.luogu.org/problem/show?pid=1281题意:题解:二分法+贪心。 二分最大时间t贪心判断t是否可行,求出最小时间T。 贪心构造解:从后向前尽量分配给靠后的人更多的书。代码:#include <bits/stdc++.h> using namespace std; typedef long long ll; #define MS(a) m

yxg_123的博客 774

CDOJ 215 吴队长征婚 DFS+剪枝

题目链接:http://acm.uestc.edu.cn/#/problem/show/215题意:题解:http://www.lai18.com/content/7765203.html 剪枝1:大木棍长度只可能是sum的约数 剪枝2:重复的木棍就可以不用枚举了 剪枝3:每次都从最长的开始枚举代码:#include <bits/stdc++.h> using namespace std; t

yxg_123的博客 576

洛谷2658 汽车拉力比赛 二分

题目链接:https://www.luogu.org/problem/show?pid=2658题意:题解:二分D,BFS判断是否可以到达全部路标。 很有道理啊,为什么T啊!代码:#include <bits/stdc++.h> using namespace std; typedef long long ll; #define MS(a) memset(a,0,sizeof(a)) #defin

yxg_123的博客 492

CodeForces Gym 100500A A. Poetry Challenge DFS

题目链接:http://codeforces.com/gym/100500/attachments题意:文字接龙,谁接不下去了,就算谁输 输出赢家 都很聪明的情况下题解:看起来是博弈 不会啊 这个dfs还不懂 qsc ls:转化成图论之后,直接DFS爆搜就好了!代码:#include <bits/stdc++.h> using namespace std; typedef long lo

yxg_123的博客 477

洛谷1462 通往奥格瑞玛的道路 二分+spfa

题目链接:https://www.luogu.org/problem/show?pid=1462题意:题解:二分法+最短路判定。二分经过城市的最大费用w,然后判定:对于每一个费用大于w的城市标记为不可达,求最短路径,判断最短路与血量的关系即可。如果一个城市不可达可以在SPFA算法开始前将inq置为1。小的优化:把f值从小到大排序,对f值进行二分就可以了。代码:#include <bits/stdc+

yxg_123的博客 462
上一篇: noip 1995 灯的排列问题 排列组合 DFS
下一篇: Codeforces Round #401 (Div. 2)A B C
yxg_123
博客等级 码龄10年 8粉丝 199原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值