#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. LeetCode#26 | Remove Duplicates from Sorted Array 删除有序数组中的重复元素

    一.题目 Description Given a sorted array, remove the duplicates in-place such that each element appear ...

  2. CentOS使用Postfix发送邮件

    1)配置hosts映射 [root@mail ~]# ifconfig ens33 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mt ...

  3. 02_TypeScript数据类型

    typescript中为了使编写的代码更规范,更有利于维护,增加了类型校验,写ts代码必须指定类型.   1.布尔类型(boolean) var flag:boolean = true;   2.数字 ...

  4. Vue路由(vue-router)

    一.介绍 1.vue-router安装 官方文档:https://router.vuejs.org/zh/installation.html下载地址:https://unpkg.com/vue-rou ...

  5. [Redis-Python]发布订阅通过Redis异步发送邮件

    接收订阅 #!/usr/bin/env pyhton # coding:utf-8 # @Time : 2020-02-16 21:36 # @Author : LeoShi # @Site : # ...

  6. [Redis-CentOS7]Redis设置连接密码(九)

    设置Redis密码 修改/etc/redis.conf 一定要强密码redis为内存存储 抗暴力破解强 requirepass password 重启服务 systemctl restart redi ...

  7. bootstrap4网格

    Bootstrap 4 网格系统有以下 5 个类: .col- 针对所有设备 .col-sm- 平板 - 屏幕宽度等于或大于 576px .col-md- 桌面显示器 - 屏幕宽度等于或大于 768p ...

  8. Shiro知识初探(更新中)

    Shiro 是当下常见的安全框架,主要用于用户验证和授权操作. RBAC 是当下权限系统的设计基础,同时有两种解释:一: Role-Based Access Control,基于角色的访问控制即,你要 ...

  9. MR25H40非易失性串行接口MRAM

    Everspin 是设计,制造和商业销售离散和嵌入式磁阻RAM(MRAM)和自旋传递扭矩MRAM(STT-MRAM)的全球领导者,其市场和应用领域涉及数据持久性和完整性,低延迟和安全性至关重要.Eve ...

  10. Bellman-ford算法 无向图

    // 单源最短路问题 // Bellman-Ford算法 // 复杂度O(V*E) //! 可以判断负圈 #include <cstdio> #include <iostream&g ...