#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. 【题解】战争系列-截获密文I

    给你一个最短代码: #include <iostream> #include <string> int main(){ std::string str; std::cin &g ...

  2. Linux学习2-云服务器上安装java和tomcat环境

    在linux上部署java的项目,首先要安装JDK和Tomcat,具体要求怎么操作呢,我们一起来学习吧! JDK的安装步骤如下: 1.首先我们从官网下载jdk-8u231-linux-x64.rpm安 ...

  3. qt creator源码全方面分析(2-10-2)

    目录 Creating Your First Plugin 创建一个插件项目 构建并运行插件 文件结构 qmake项目 插件元数据模板 插件类 头文件 源文件 Creating Your First ...

  4. ssh连接超时的问题

    vi /etc/ssh/sshd_config ClientAliveInterval ClientAliveCountMax # 注: # ClientAliveInterval选项定义了每隔多少秒 ...

  5. Linux中查看日志文件的正确姿势,求你别tail走天下了!

    作为一个后端开发工程师,在Linux中查看查看文件内容是基本操作了.尤其是通常要分析日志文件排查问题,那么我们应该如何正确打开日志文件呢?对于笔者这种小菜鸡来说,第一反应就是 cat,tail,vi( ...

  6. VFP的数据策略:基础篇

    VFP的数据策略:基础篇 概述 在VFP应用程序中,有很多方法可以访问非VFP数据(如SQL Server):远程视图.SQ LPassthrough.ADO.XML……本文件将审查不同机制的利弊,并 ...

  7. shell脚本 监控ps 不存在则重启

    监控 tomcat ,如果自动停止了,则重新启动 #!/bin/bash Start=/usr/local/apache-tomcat-8.0.24/bin/startup.sh Url=" ...

  8. centos6.x下yum安装heartbeat

    [root@heartbeat ~]# uname -n #<===配置heartbeat时,节点的主机名必须和 uname -n 命令的结果要一致 heartbeat [root@heartb ...

  9. C#后台异步消息队列实现

    简介 基于生产者消费者模式,我们可以开发出线程安全的异步消息队列. 知识储备 什么是生产者消费者模式? 为了方便理解,我们暂时将它理解为垃圾的产生到结束的过程. 简单来说,多住户产生垃圾(生产者)将垃 ...

  10. springboot无法访问静态资源

    无法访问static下的静态资源 1.在application.yml中添加 resources: static-locations: classpath:/META-INF/resources/,c ...