#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 多源搜索的更多相关文章

  1. CodeForces - 1105D Kilani and the Game(多源BFS+暴力)

    题目: 给出一张游戏地图和每个玩家的位置,每次能移动的步数.p个玩家轮流移动占领地图中的格子(当格子已经被占领时就不能在占领了)在每个玩家都不能移动时游戏结束. 问在游戏结束后,每个玩家占领的格子的数 ...

  2. 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 ...

  3. 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 ...

  4. Codeforces C. NP-Hard Problem 搜索

    C. NP-Hard Problem time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  5. Codeforces 1105D Kilani and the Game【BFS】

    <题目链接> 题目大意: 每个玩家控制一个颜色去扩张,每个颜色的扩张有自己的速度,一个颜色跑完再跑下一种颜色.在所有颜色不能在继续扩张的时候停止游戏.询问此时各种颜色的数量. 解题分析: ...

  6. Codeforces 1105D(双层广搜)

    要点 题意:可以拐弯,即哈密顿距离 注意不可以直接一个一个搜,这过程中会把下一轮的标记上,导致同一轮的其它点没能正常完成应有的搜索 因此采用双层广搜,把同一轮先都出队列再的一起搜 #include & ...

  7. codeforces 1006 F(折半搜索)

    F. Xor-Paths time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...

  8. Codeforces 1105D (BFS)

    题面 传送门 分析 考虑BFS while(棋盘没有满){ for 玩家 p{ 对p进行BFS,走s[p]步 } } 对于每个玩家p BFS的时候如果到了格子(x,y),就把\(vis[x][y]\) ...

  9. E - Petya and Exam CodeForces - 832B 字典树+搜索

    E - Petya and Exam CodeForces - 832B 这个题目其实可以不用字典树写,但是因为之前写过poj的一个题目,意思和这个差不多,所以就用字典树写了一遍. 代码还是很好理解的 ...

随机推荐

  1. angularJS 格式化日期 转载

    angularjs中的filter(过滤器)——格式化日期的date 标签: filterangularjsdate http://blog.csdn.net/smile_panda/article/ ...

  2. 实例探究Aspectj,解析SentinelResourceAspect

    为了学习SentinelResourceAspect,这篇文章里我用Aspectj实现一个AOP实例,一起来看下. Sentinel 提供了 @SentinelResource 注解用于定义资源,支持 ...

  3. python笔记22(面向对象课程四)

    今日内容 讲作业 栈 顺序查找 可迭代对象 约束 + 异常 反射 内容详细 1.作业 1.1 代码从上到下执行 print('你好') def func(): pass func() class Fo ...

  4. GitBook安装部署实操手册

    前言 GitBook是一个基于Node.js的命令行工具,可使用Git和Markdown来编写文档,赞誉太多,不再赘述. Node.js 下载安装包 cd /tmp wget https://node ...

  5. Python 协程 - Coroutines

    协程 - Coroutines Awaitable Objects, Awaitable Objects 通常由 __await__() 生成, 而 Coroutine objects 是由 asyn ...

  6. vue hash模式下微信分享后打开首页,三种完美解决方案

    微信分享功能给我们带来了很大的便利,使得基于微信开发出来的 H5 页面可以很好的通过微信平台进行传播.所以呢,基本上每个基于微信开发的 H5 都会集成微信分享功能.但是,前几天在对接微信分享 API ...

  7. Day4前端学习之路——背景边框列表链接和更复杂的选择器

    课程目标 掌握 CSS 稍微复杂的一些选择器,还有背景,边框等一些 CSS 样式属性 主要内容: 背景属性 边框 列表 链接 其他选择器 选择器概览:https://www.w3school.com. ...

  8. SpringBoot图文教程7—SpringBoot拦截器的使用姿势这都有

    有天上飞的概念,就要有落地的实现 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例都敲一遍 先赞后看,养成习惯 SpringBoot 图文教程系列文章目录 SpringBoot图文教程1「概念+ ...

  9. npm/gulp/nodejs

    npm淘宝镜像:https://npm.taobao.org/ vscode先安装npm淘宝镜像 再安装gulp:https://www.cnblogs.com/xiaoleiel/p/1116056 ...

  10. 初识matlab

    1 matlab概貌 MATLAB是MATrix LABoratory(矩阵实验室)的缩写,是一款由美国The MathWorks公司出品的商业数学软件.matlab是一种用于算法开发.数据可视化.数 ...