题目链接: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. LeetCode 429. N叉树的层序遍历(N-ary Tree Level Order Traversal)

    429. N叉树的层序遍历 429. N-ary Tree Level Order Traversal LeetCode429. N-ary Tree Level Order Traversal 题目 ...

  2. Spring Boot制作启动图案

    SpringBoot在启动时会有一个默认图案的,如果不喜欢可以自己制作一个. 在resources的目录下新建banner.txt文件. 制作图案地址:springboot启动图案定制 通过输入字符串 ...

  3. 修改织梦DedeCMS投票漏洞

    织梦/dedecms系统我们都知道是有很多漏洞的,我在调试投票功能的时候正好要用到投票功能,这不就出现了漏洞,下面我就给大家展示如何修复这个织梦投票漏洞 首先我们打开//dedevote.class. ...

  4. Python进阶:聊协程

    从一个爬虫说起 Python 2 的时代使用生成器协程,Python 3.7 提供了新的基于 asyncio 和 async / await 的方法.先看一个简单的爬虫代码,爬虫的 scrawl_pa ...

  5. C++ new/delete详解及原理

    学了冯诺依曼体系结构,我们知道: 硬件决定软件行为,数据都是围绕内存流动的. 可想而知,内存是多么重要.当然,我们这里说的内存是虚拟内存(详情看Linxu壹之型). 1.C/C++内存布局 2.C语言 ...

  6. k8s安装ingress

    1. 环境准备 安装nginx-ingress-controller和backend cd /etc/yum.repos.d/mainfests 下载镜像的脚本 vi ingressnginx.sh ...

  7. AtCoder Grand Contest 034

    A:如果C在D左侧,显然先让B到达终点再让A走即可,否则先判断一下A是否可以在某处超过B.也就是先判断一下起点与终点之间是否有连续的障碍,若有则无解:然后若C在D左侧输出Yes,否则判断B和D之间是否 ...

  8. Tomcat HTTP connector和AJP connector

    Tomcat服务器通过Connector连接器组件与客户程序建立连接,“连接器”表示接收请求并返回响应的端点.即Connector组件负责接收客户的请求,以及把Tomcat服务器的响应结果发送给客户. ...

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

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

  10. 代码审计:covercms 1.6

    小菜只能找找没人用的cms练练手了 cnvd上有个 CoverCMS V1.16存在多个漏洞 漏洞描述 :CoverCMS V1.16存在重装.信息泄露.暴力破解.存储型跨站脚本和反射型跨站脚本漏洞. ...