题目链接: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. java junit4-JUnit测试报 No socket available 错误

    问题描述 JUnit测试报 No socket available 错误 Eclipse进行JUnit测试时,总弹出 No socket available 窗口,导致测试不能进行. 解决方案一: 打 ...

  2. IIS清理缓存

    服务器突然断电经常会导致IIS中web项目运行不起来问题,各种报XXXX.dll加载失败,解决方法重新发布,如果重新发布也不行可能就是IIS缓存的问题了. 清理IIS缓存方法: 进入以下文件夹吧对应的 ...

  3. Linux 进程控制

    分享知乎上看到的一句话,共勉: 学习周期分为学习,思考,实践,校正四个阶段,周期越短,学习效率越高. 前面讲的都是操作系统如何管理进程,接下来,看看用户如何进行进程控制. 1.进程创建 先介绍一下函数 ...

  4. Fabric交易流程

    (内容可能有些乱,请见谅,日后会对格式进行整理!) #### 在1.0及以后的版本中,客户端应用会先向Fabric CA申请用户所需要的Fabric中的准入证书,用于签名提案以及交易,然后由客户端(A ...

  5. 解决找不到mkfs.ubifs命令

    解决找不到mkfs.ubifs命令 ubuntu 版本:14.04 sudo apt-get update sudo apt-get install mtd-utils sudo apt-get in ...

  6. PHP Math函数

    abs() 绝对值.   acos() 反余弦.   acosh() 反双曲余弦.   asin() 反正弦.   asinh() 反双曲正弦.   atan() 反正切.   atan2() 两个参 ...

  7. collections.defaultdict()的使用

    这里的defaultdict(function_factory)构建的是一个类似dictionary的对象,其中keys的值,自行确定赋值,但是values的类型,是function_factory的 ...

  8. Python之(matplotlib、numpy、pandas)数据分析

    一.Matplotlib 是一个 Python 的 2D绘图库,它以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形. 它主要用来回事图形,用来展现一些数据,更加直观的展示,让你第一眼就只要数 ...

  9. tslint 忽略格式检查

    // tslint:disable——忽略该行以下所有代码出现的错误提示,可以在文件首行添加达到忽略整个文件的格式提示 // tslint:enable——当前ts文件重新启用tslint// tsl ...

  10. Suricata Rules

    Suricata Rules https://redmine.openinfosecfoundation.org/projects/suricata/wiki/Suricata_Rules https ...