题目链接:https://codeforces.com/contest/1105/problem/D

题意:p 个人在 n * m 的地图上扩展自己的城堡范围,每次最多走 a_i 步(曼哈顿距离),按 1 ~ p 的顺序,问最后每个人占领的点的数量。

题解:用一个队列维护当前起点,用另一个队列模拟当前起点走 a_i 步可以到达的全部点。(60 ~ 63行关键代码,多源bfs,不可分开跑)

    数据:

    4 3 2
    2 1
    1..
    1..
    ..2
    ...

    output:10 2

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
#define lowbit(x) ((x)&(-x))
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const int maxn = 1e3 + ;
const int maxm = 1e6 + ;
const ll mod = 1e9 + ; int n,m,p;
char s[maxn][maxn];
int a[],vis[maxn][maxn];
int dx[] = {-,,,};
int dy[] = {,-,,}; struct node {
int x,y,d;
}; bool judge(int x,int y) {
if(x <= || x > n || y <= || y > m || s[x][y] == '#') return false;
return true;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
scanf("%d%d%d",&n,&m,&p);
for(int i = ; i <= p; i++) scanf("%d",&a[i]);
for(int i = ; i <= n; i++) {
scanf("%s",s[i] + );
for(int j = ; j <= m; j++) vis[i][j] = -;
}
queue<pii>q;
for(int k = ; k <= p; k++) {
for(int i = ; i <= n; i++) {
for(int j = ; j <= m; j++) {
if(s[i][j] - '' == k) {
q.push(mp(i,j));
vis[i][j] = k;
}
}
}
}
while(!q.empty()) {
pii now = q.front();
q.pop();
int x = now.first, y = now.second;
queue<node>q1;
q1.push({x,y,a[vis[x][y]]});
while(!q.empty() && vis[q.front().first][q.front().second] == vis[x][y]) {
q1.push({q.front().first,q.front().second,a[vis[x][y]]});
q.pop();
}
while(!q1.empty()) {
node hh = q1.front();
q1.pop();
if(hh.d <= ) continue;
for(int i = ; i < ; i++) {
int nx = hh.x + dx[i], ny = hh.y + dy[i], d = hh.d;
if(judge(nx,ny) && vis[nx][ny] == -) {
vis[nx][ny] = vis[x][y];
q1.push({nx,ny,d - });
q.push(mp(nx,ny));
}
}
}
}
int ans[] = {};
for(int i = ; i <= n; i++) {
for(int j = ; j <= m; j++) {
if(vis[i][j] != -) ans[vis[i][j]]++;
}
}
for(int i = ; i <= p; i++) printf("%d ",ans[i]);
return ;
}

Codeforces Round #533 (Div. 2) D. Kilani and the Game(BFS)的更多相关文章

  1. Codeforces Round #529 (Div. 3) E. Almost Regular Bracket Sequence (思维)

    Codeforces Round #529 (Div. 3) 题目传送门 题意: 给你由左右括号组成的字符串,问你有多少处括号翻转过来是合法的序列 思路: 这么考虑: 如果是左括号 1)整个序列左括号 ...

  2. Codeforces Round #356 (Div. 2) C. Bear and Prime 100(转)

    C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standar ...

  3. Codeforces Round #533(Div. 2) D.Kilani and the Game

    链接:https://codeforces.com/contest/1105/problem/D 题意: 给n*m的地图,最多9个人,同时有每个人的扩张次数(我开始以为是直线扩张最大长度..实际是能连 ...

  4. Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS

    题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...

  5. Codeforces Round #533 (Div. 2) C. Ayoub and Lost Array(递推)

    题意: 长为 n,由 l ~ r 中的数组成,其和模 3 为 0 的数组数目. 思路: dp[ i ][ j ] 为长为 i,模 3 为 j 的数组数目. #include <bits/stdc ...

  6. Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation(贪心)

    题目:http://codeforces.com/contest/389/problem/C 题意:给n个箱子,给n个箱子所能承受的重量,每个箱子的重量为1: 很简单的贪心,比赛的时候没想出来.... ...

  7. Codeforces Round #290 (Div. 2) B. Fox And Two Dots(DFS)

    http://codeforces.com/problemset/problem/510/B #include "cstdio" #include "cstring&qu ...

  8. Codeforces Round #603 (Div. 2) C. Everyone is a Winner! (数学)

    链接: https://codeforces.com/contest/1263/problem/C 题意: On the well-known testing system MathForces, a ...

  9. Codeforces Round #509 (Div. 2) F. Ray in the tube(思维)

    题目链接:http://codeforces.com/contest/1041/problem/F 题意:给出一根无限长的管子,在二维坐标上表示为y1 <= y <= y2,其中 y1 上 ...

随机推荐

  1. redis 那些事儿

    1 我的数据存入redis了但是怎么不见了? redis的内存使用是有限的,一直向redis中写入数据(如果配置了allkeyLRU)就会触发内存淘汰机制,将最近没有访问过的的key,value删除掉 ...

  2. [转帖]TPC-C解析系列04_TPC-C基准测试之数据库事务引擎的挑战

    TPC-C解析系列04_TPC-C基准测试之数据库事务引擎的挑战   http://www.itpub.net/2019/10/08/3331/ OceanBase这次TPC-C测试与榜单上Oracl ...

  3. Django开发常用方法及面试题

    目录 1.对Django的认识? 2.Django .Flask.Tornado的对比 3.什么是wsgi,uwsgi,uWSGI? 4. django请求的生命周期? 5. 简述什么是FBV和CBV ...

  4. 20191104-基于Python计数排序算法分析

    计数排序 计数排序算法没有用到元素间的比较,它利用元素的实际值来确定它们在输出数组中的位置,也就是说元素从未排序状态变为已排序状态的过程,是由额外空间的辅助和元素本身的值决定的,将每个元素出现的次数记 ...

  5. AJAX一些注释掉的语句

    var sysdept=JSON.parse(localStorage.getItem("loginSysUser")); for(var o in sysdept){ alert ...

  6. Manjaro 使用基础

    一.pacman/yay 的基础命令 Manjaro 装好后,需要运行的第一条命令: sudo pacman -Syy ## 强制更新包数据 sudo pacman-mirrors --interac ...

  7. protobuf的使用(netty传输多种对象类型)

    重点是: 1.枚举DataType的定义 2.oneof的使用

  8. Java8新特性 - 并行流与串行流

    并行流就是把一个内容分成多个数据块,并用不同的线程分别处理每个数据块的流. Java8中将并行进行了优化,我们可以很容易的对数据进行并行操作.Stream API可以声明性地通过parallel()和 ...

  9. 第一章 Java的IO演进之路

    Unix中5种IO模型 就网络通信而言,一次数据读入可以分为两个阶段,首先等待数据从网络中到达,到达后需要复制到内核的缓冲区中,第二个阶段是从内核的缓冲区复制到进程的缓冲区,复制到进程的缓冲区才算读取 ...

  10. SaltStack实现动态文件分发,支持脚本换行,中文乱码

    场景:将动态脚本分发到各个机器的指定目录下 说明:使用SaltStack的 file.managed file.managed 里面可以定义内容的几种方式 - source: - contents: ...