Codeforces Round #533 (Div. 2) D. Kilani and the Game(BFS)
题目链接: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)的更多相关文章
- Codeforces Round #529 (Div. 3) E. Almost Regular Bracket Sequence (思维)
Codeforces Round #529 (Div. 3) 题目传送门 题意: 给你由左右括号组成的字符串,问你有多少处括号翻转过来是合法的序列 思路: 这么考虑: 如果是左括号 1)整个序列左括号 ...
- 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 ...
- Codeforces Round #533(Div. 2) D.Kilani and the Game
链接:https://codeforces.com/contest/1105/problem/D 题意: 给n*m的地图,最多9个人,同时有每个人的扩张次数(我开始以为是直线扩张最大长度..实际是能连 ...
- Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS
题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...
- Codeforces Round #533 (Div. 2) C. Ayoub and Lost Array(递推)
题意: 长为 n,由 l ~ r 中的数组成,其和模 3 为 0 的数组数目. 思路: dp[ i ][ j ] 为长为 i,模 3 为 j 的数组数目. #include <bits/stdc ...
- Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation(贪心)
题目:http://codeforces.com/contest/389/problem/C 题意:给n个箱子,给n个箱子所能承受的重量,每个箱子的重量为1: 很简单的贪心,比赛的时候没想出来.... ...
- Codeforces Round #290 (Div. 2) B. Fox And Two Dots(DFS)
http://codeforces.com/problemset/problem/510/B #include "cstdio" #include "cstring&qu ...
- 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 ...
- Codeforces Round #509 (Div. 2) F. Ray in the tube(思维)
题目链接:http://codeforces.com/contest/1041/problem/F 题意:给出一根无限长的管子,在二维坐标上表示为y1 <= y <= y2,其中 y1 上 ...
随机推荐
- Ribbon学习笔记
微服务的概念: Ribbon默认的是轮询的算法: @LoadBalanced @EnableEurekaClient Irule是根据 Ribbon默认(轮询)的7中负载均衡的算法: 修改默认的R ...
- PyTorch 常用代码段整理
基础配置 检查 PyTorch 版本 torch.__version__ # PyTorch version torch.version.cuda ...
- fputcsv 导出excel,解决内存、性能、乱码、科学计数法问题
在PHP的日常开发中,时常会需要导出 excel ,一般我们会使用 PHPExcel ,性能强大,但是在数据量大的时候,phpexcel 性能差.内存溢出等各种不可控问题就会出现.因此,如果对导出样式 ...
- 嵌入式Linux学习笔记之第二阶段---文件I/O
1.文件IO的四个函数 一些术语: 不带缓冲的I/O: 每个read和write都调用内核中的一个系统调用. 文件描述符: 一个非负整数,对内核而言,所以打开的文件都通过文件描述符引用. ①打开或创建 ...
- 『Python基础』第8节:格式化输出
现在有一个需求, 询问用户的姓名, 年龄, 工作, 爱好, 然后打印成以下格式 ************ info of Conan ************ name: Conan age: 23 ...
- vijo 1456最小总代价
题意:中文题... 题解:状态比较多,可以说是状压的基础题吧,我们定义dp[i][j],j为一个二进制数,每位0表示接触过该物品,1表示没有接触过;j表示当前物品在谁手上.递推的顺序注意一下就好 ac ...
- zabbix4.2的yum+mariadb方式部署安装
本文依据官方文档操作(英文4.2):https://www.zabbix.com/documentation/4.2/manual/installation/install_from_packages ...
- 采用localStorage做定时缓存
背景 页面采用ajax获取数据时,每访问一次就会发送一次请求向服务端获取数据,可是呢. 有些数据更新的又不频繁,所以我就想着使用localStorage进行本地存储,然后在固定间隔时在去更新数据.(下 ...
- vue组件间的数据传递
父组件向子组件传递数据 在 Vue 中,可以使用 props 向子组件传递数据. App.vue HelloWorld.vue 在子组件部分: 如果需要从父组件获取 logo 的值,就需要使用 p ...
- iOS开发-NSString去掉所有换行及空格
1.去掉字符串两端的空格及回车 - (NSString *)removeSpaceAndNewline:(NSString *)str{ NSString *temp = [str stringByT ...