中石油12203-Darker and Darker
题目描述
We will repeatedly perform the following operation until all the squares are black:
Every white square that shares a side with a black square, becomes black.
Find the number of operations that will be performed. The initial grid has at least one black square.
Constraints
·1≤H,W≤1000
·Aij is # or ..
·The given grid has at least one black square.
输入
H W
A11A12...A1W
:
AH1AH2...AHW
输出
样例输入
复制样例数据
3 3
...
.#.
...
样例输出
2
提示
After one operation, all but the corners of the grid will be black. After one more operation, all the squares will be black.
就不翻译了
思路:广度优先搜索 模板题
自己写的代码:
1 #include<bits/stdc++.h>2 using namespace std;3 typedef long long ll;4 int vis[1005][1005];5 char arr[1005][1005];6 int main(){7 int n,m;cin>>n>>m;8 for(int i=1;i<=n;i++){9 scanf("%s",arr[i]+1);
10 }
11 memset(vis,-1,sizeof(vis));
12 typedef pair<int,int>P;
13 queue<P>que;
14 for(int i=1;i<=n;i++){
15 for(int j=1;j<=m;j++){
16 if(arr[i][j]=='#') {
17 vis[i][j]=0;
18 que.push(P(i,j));
19 }
20 }
21 }
22 int maxx=0;
23 while(!que.empty()){
24 P p=que.front();que.pop();
25 if(p.first-1>0&&vis[p.first-1][p.second]==-1){
26 vis[p.first-1][p.second]=vis[p.first][p.second]+1;
27 que.push(P(p.first-1,p.second));
28 maxx=max(maxx,vis[p.first][p.second]+1);
29 }
30 if(p.first+1<=n&&vis[p.first+1][p.second]==-1){
31 vis[p.first+1][p.second]=vis[p.first][p.second]+1;
32 que.push(P(p.first+1,p.second));
33 maxx=max(maxx,vis[p.first][p.second]+1);
34 }
35 if(p.second-1>0&&vis[p.first][p.second-1]==-1){
36 vis[p.first][p.second-1]=vis[p.first][p.second]+1;
37 que.push(P(p.first,p.second-1));
38 maxx=max(maxx,vis[p.first][p.second]+1);
39 }
40 if(p.second+1<=m&&vis[p.first][p.second+1]==-1){
41 vis[p.first][p.second+1]=vis[p.first][p.second]+1;
42 que.push(P(p.first,p.second+1));
43 maxx=max(maxx,vis[p.first][p.second]+1);
44 }
45 }
46 cout<<maxx<<endl;
47 return 0;
48 }
大神写的代码:
1 #include<bits/stdc++.h>2 using namespace std;3 const int maxn=1e5+5;4 const int dx[]={1,-1,0,0};5 const int dy[]={0,0,1,-1};6 7 int n,m,ans;8 char s[1111][1111];9 struct node { int x,y,step; };
10 queue<node> que;
11 void bfs() {
12 while (!que.empty()) {
13 node now=que.front(); que.pop();
14 ans=max(ans,now.step);
15 for (int i=0;i<4;i++) {
16 node nex=node{now.x+dx[i],now.y+dy[i],now.step+1};
17 if (s[ nex.x ][ nex.y ]=='.') {
18 s[ nex.x ][ nex.y ]='#';
19 que.push(nex);
20 }
21 }
22 }
23 }
24 int main () {
25 scanf("%d%d",&n,&m);
26 for (int i=1;i<=n;i++)
27 for (int j=1;j<=m;j++) {
28 scanf(" %c",&s[i][j]);
29 if (s[i][j]=='#')
30 que.push(node{i,j,0});
31 }
32 bfs();
33 printf("%d\n",ans);
34 return 0;
35 }
总结:刚开始的时候竟然往dfs上面想了,看来是好久没见bfs的题了,都不会做了。另外代码跟神犇写的差距太大了,要好好学习别人的代码呀。
蒟蒻一枚;
中石油12203-Darker and Darker相关推荐
- Darker and Darker(宽搜)
Darker and Darker(宽搜) 题目描述 You are given a grid of squares with H horizontal rows and W vertical col ...
- 中石油2018年秋季C语言 试卷答案,[石油华东]《数据采集系统》2018年秋季学期在线作业...
<数据采集系统>2018年秋季学期在线作业(一) 中石油华东作业资料www.op5n.com整理提供 一.单选题: 1.[单选题]n路的多路模拟开关,每路断开的开关的漏电流均为IR,开关的 ...
- 中石油在意大利加油站0.5分/升,会不会赔死啊?
中石油在意大利新开加油站无论柴油还是汽油只需要0.5欧分/每升,看到这个消息,广大网友都炸天了,为啥油价这么低呢?这是不是双重标准呢?要是加满10次,免费送一辆兰博基尼那不是更带劲? 我们先来看一下事 ...
- 与中石油分享SOA成功实践
中国石油天然气集团公司的"生产运行管理系统"系统是一个地域上覆盖了中国石油十大油田,业务领域涵盖了物理勘探.钻井工程.测井.录井.试油和井下作业等专业应用的信息管理系统.在这个项目 ...
- 中石油布局天然气商储 天然气国家储备有望
http://www.sina.com.cn 2007年09月29日 09:12 华夏时报 本报记者 王冰凝 北京报道 9月26日,总投资90.22亿元,中石油大连液化天然气(以下简称LNG)项目在大 ...
- 俄油与中石油达成为期10年的协议;苏伊士完成股东联合体收购,苏冰岚履职首席执行官 | 能动...
石油和化工 燕山石化制氢项目顺利通过依据T/CAB 0078-2020<低碳氢.清洁氢及可再生氢标准及评级>的审核,并获得由TUV南德意志集团颁发的全国首张清洁氢证书.作为2022年北京冬 ...
- 拆分中石油:多种方案流传 但启动阻力重重
公司报道时代周报张蕊2013-10-10 00:25 我要分享 腾讯微博 QQ空间 QQ好友 新浪微博 2512 转播到腾讯微博 本报记者 张蕊 发自北京 余勇最近的生活已经完全被打乱了,他已经半个月 ...
- 中石油、长安、奥动新能源合作打造换电站;玛氏箭牌与阿里巴巴合作同城零售 | 美通企业日报...
今日看点:中石油.长安.奥动三方合作全国首座综合能源站.玛氏箭牌与阿里巴巴同城零售事业群达成同城汇战略合作.奢侈品电商Mytheresa公司上市.岭南酒店品牌布局加速度,2020年新签27个项目.雅高 ...
- 中石油即时通手机版显示服务器登录失败,中石油即时通手机最新版app
中石油即时通手机最新版app这是一款专注于中国石油集团内部员工的即时通讯软件,软件包括工作看板.网络日程.项目计划.待办事宜.工作日志.签到考勤.云记事本.新闻公告.通知.工作流审批.移动客户管理等常 ...
- 中石油中石化的数字化变革:中国石油数字化油田迈入物联网与云计算时代!
中国石油数字化油田迈入物联网与云计算时代! 中国石油全面推进"十二五"信息技术总体规划实施,一批批数字化油田相继迈上新台阶,在为全面建成世界水平综合性国际能源公司,努力实现信息化与 ...
最新文章
- 选红叶家装不就得了,用得着这么费事吗?!
- shell 的 功能语句--1
- mysql修改编码格式6_修改编码格式MySQL
- Fastboot的安装与使用
- 数学建模——智能优化之粒子群模型详解Python代码
- Servlet异常处理
- Vue + Nodejs + Express 解决跨域的问题
- 漫画:什么是volatile关键字?(整合版)
- [vue] 说说你对proxy的理解
- boost::interprocess::named_mutex的翻译和学习
- 2020年度电竞营销行业报告
- 关于(我们流量表优化),分区表数据块过多,聚合又导致数据倾斜问题
- pandas 根据两列数据筛选dataframe
- Codeforces Global Round 14, C. Phoenix and Towers
- MySQL之终端(Terminal)管理MySQL
- The Classic IQ Test
- SSH学习之一 OpenSSH基本使用
- 开源cnc软件_带有开源软件的CNC铣削
- 工作也能用 Tinder 配对?一家叫 Palaround 的公司就在做这门生意
- 做H5页面用什么软件比较好?3款易上手好用的H5网页编辑工具