CodeForces - 1105D 多源搜索
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
int x,y;
ll setp;
};
queue<node> Q,border[];
const int maxn=;
char a[maxn][maxn];
int vis[maxn][maxn];
int n,m,p;
ll ans[],s[];
int f[][]={
{,},{,},{,-},{-,}
};
void bfs(int w)
{
node temp;
int x,y;
while(!Q.empty())
{
temp=Q.front();
Q.pop();
if(temp.setp==)
border[w].push(temp);
else{
for(int i=;i<;i++)
{
x=temp.x+f[i][];
y=temp.y+f[i][];
if(x<||x>n||y<||y>m||vis[x][y]!=||a[x][y]!='.') continue;
vis[x][y]=w;
Q.push(node{x,y,temp.setp-});
}
}
}
}
bool expand(int w)
{
node temp;
while(!border[w].empty())
{
temp=border[w].front();
border[w].pop();
temp.setp=s[w];
Q.push(temp);
}
bfs(w);
return !border[w].empty();
}
int main()
{
cin>>n>>m>>p;
for(int i=;i<=p;i++)
cin>>s[i];
for(int i=;i<=n;i++)
cin>>a[i]+;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(a[i][j]>=''&&a[i][j]<='')
{
int num=a[i][j]-'';
border[num].push(node{i,j,s[num]});
vis[i][j]=num;
}
}
}
while()
{
bool flag= false;
for(int i=;i<=p;i++)
flag|=expand(i);
if(!flag)
break;
}
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
ans[vis[i][j]]++;
for(int i=;i<=p;i++)
cout<<ans[i]<<" ";
}
CodeForces - 1105D 多源搜索的更多相关文章
- CodeForces - 1105D Kilani and the Game(多源BFS+暴力)
题目: 给出一张游戏地图和每个玩家的位置,每次能移动的步数.p个玩家轮流移动占领地图中的格子(当格子已经被占领时就不能在占领了)在每个玩家都不能移动时游戏结束. 问在游戏结束后,每个玩家占领的格子的数 ...
- Codeforces 799D Field expansion - 搜索 - 贪心
In one of the games Arkady is fond of the game process happens on a rectangular field. In the game p ...
- Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索
Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...
- Codeforces C. NP-Hard Problem 搜索
C. NP-Hard Problem time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- Codeforces 1105D Kilani and the Game【BFS】
<题目链接> 题目大意: 每个玩家控制一个颜色去扩张,每个颜色的扩张有自己的速度,一个颜色跑完再跑下一种颜色.在所有颜色不能在继续扩张的时候停止游戏.询问此时各种颜色的数量. 解题分析: ...
- Codeforces 1105D(双层广搜)
要点 题意:可以拐弯,即哈密顿距离 注意不可以直接一个一个搜,这过程中会把下一轮的标记上,导致同一轮的其它点没能正常完成应有的搜索 因此采用双层广搜,把同一轮先都出队列再的一起搜 #include & ...
- codeforces 1006 F(折半搜索)
F. Xor-Paths time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces 1105D (BFS)
题面 传送门 分析 考虑BFS while(棋盘没有满){ for 玩家 p{ 对p进行BFS,走s[p]步 } } 对于每个玩家p BFS的时候如果到了格子(x,y),就把\(vis[x][y]\) ...
- E - Petya and Exam CodeForces - 832B 字典树+搜索
E - Petya and Exam CodeForces - 832B 这个题目其实可以不用字典树写,但是因为之前写过poj的一个题目,意思和这个差不多,所以就用字典树写了一遍. 代码还是很好理解的 ...
随机推荐
- 题解 bzoj1954【Pku3764 The xor – longest Path】
做该题之前,至少要先会做这道题. 记 \(d[u]\) 表示 \(1\) 到 \(u\) 简单路径的异或和,该数组可以通过一次遍历求得. \(~\) 考虑 \(u\) 到 \(v\) 简单路径的异或和 ...
- 突破CRUD | 万能树工具类封装
0.学完本文你或许可以收获 感受一个树工具从初始逐步优化完善的过程 树工具封装的设计思考与实现思路 最后收获一款拿来即用的树工具源代码 对于前端树组件有一定了解和使用过的同学可直接跳跃到第3章节开始. ...
- Xcode11: 删除默认Main.storyBoard, 自定义UIWindow的变化 UIWindow 不能在AppDelegate中处理
Xcode自动新增了一个SceneDelegate文件,查找了一下官方文档WWDC2019:Optimizing App Launch 发现,iOS13中appdelegate的职责发现了改变: iO ...
- qt creator源码全方面分析(2-10-5)
目录 The Plugin Manager, the Object Pool, and Registered Objects 插件管理器 对象池和已注册对象 The Plugin Manager, t ...
- 我说我了解集合类,面试官竟然问我为啥HashMap的负载因子不设置成1!?
在Java基础中,集合类是很关键的一块知识点,也是日常开发的时候经常会用到的.比如List.Map这些在代码中也是很常见的. 个人认为,关于HashMap的实现,JDK的工程师其实是做了很多优化的,要 ...
- Gong服务实现平滑重启分析
平滑重启是指能让我们的程序在重启的过程不中断服务,新老进程无缝衔接,实现零停机时间(Zero-Downtime)部署: 平滑重启是建立在优雅退出的基础之上的,之前一篇文章介绍了相关实现:Golang中 ...
- codewars--js--Convert all the cases!
问题描述: In this kata, you will make a function that converts between camelCase, snake_case, and kebab- ...
- 新手必看:PyCharm安装教程,Python开发者的有力工具
PyCharm是由JetBrains打造的一款Python IDE,VS2010的重构插件Resharper就是出自JetBrains之手. 同时支持Google App Engine,PyCharm ...
- 封装dropdown模块(使用到之前写好的动画组件,封装下拉菜单)
用 showhide 改写dropdown 模块: 1.首先在 css中新增动画相关样式 /*showhide组件的样式*/ .fadeOut{ opacity:; visibility: hidde ...
- 五分钟后,你将真正理解MySQL事务隔离级别!
什么是事务? 事务是一组原子性的SQL操作,所有操作必须全部成功完成,如果其中有任何一个操作因为崩溃或其他原因无法执行,那么所有的操作都不会被执行.也就是说,事务内的操作,要么全部执行成功,要么全部执 ...