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的一个题目,意思和这个差不多,所以就用字典树写了一遍. 代码还是很好理解的 ...
随机推荐
- Asp.Net Core IdentityServer4 管理面板集成
前言 IdentityServer4(以下简称 Id4) 是 Asp.Net Core 中一个非常流行的 OpenId Connect 和 OAuth 2.0 框架,可以轻松集成到 Asp.Net C ...
- 多用as少用强制类型转换
在 C# 中存在一个名叫静态类型检查的机制,这个机制可以让编译器帮助我们把类型不服的用法找出来,从而使得应用程序在运行期间加少一些类型检查的操作.但是有时候我们还是需要进行运行期类型检查,比如我们在设 ...
- Go语言实现:【剑指offer】翻转单词顺序列
该题目来源于牛客网<剑指offer>专题. 例如,"student. a am I",正确的句子应该是"I am a student." Go语言实 ...
- Rip 动态路由协议
路由信息协议(RIP) 是内部网关协议IGP中最先得到广泛使用的协议. Routing Information Protocol) RIP是一种分布式的基于距离矢量的路由 ...
- vue 的点击事件怎么获取当前点击的元素
手机赚钱怎么赚,给大家推荐一个手机赚钱APP汇总平台:手指乐(http://www.szhile.com/),辛苦搬砖之余用闲余时间动动手指,就可以日赚数百元 首先 vue的点击事件 是用 @cl ...
- codewars--js--the highest and lowest number + JS 字符串和数组相关知识
本文参考: http://blog.csdn.net/tyrionj/article/details/78653426 http://www.runoob.com/jsref/jsref-obj-st ...
- 【POJ - 2533】Longest Ordered Subsequence (最长上升子序列 简单dp)
Longest Ordered Subsequence 搬中文 Descriptions: 给出一个序列,求出这个序列的最长上升子序列. 序列A的上升子序列B定义如下: B为A的子序列 B为严格递增序 ...
- 二、Nginx配置实例
Nginx配置实例 一.反向代理 实例一 1.实现效果 打开浏览器,在浏览器地址栏输入地址 www.123.com ,跳转到linux系统tomcat主页面中. 2.准备工作 在linux系统中安装t ...
- mysql 主主备份
1.1.主主备份原理. 主主备份实际上是互为主从,主要是为了去缓解写入压力. 1.2.环境准备 两台机器ip分别为 100.100.100.105 (主1) 100.100.100.106(主2) 安 ...
- MySQL第七课
统计记录条数 SELECT COUNT(*) FROM 表名; SUM():总和 AVG():平均值 MAX():最大值 MIN():最小值 排序: SELECT 字段名 FROM 表名 ORDE ...