题目大意:给出一个$n\times m(n,m\leqslant10^3)$的地图,有$k(k\leqslant9)$个玩家,第$i$个玩家速度为$s_i$。地图中$\#$代表障碍;$.$ 代表空地;数字代表是一名编号为此数字的玩家的城堡。每个玩家按编号轮流操作,每次操作把自己城堡周围$s_i$格内的空地变成自己城堡。直到没有玩家能操作为止。输出每名玩家城堡的个数。

题解:$bfs$,显然发现每个点只会扩展一次,用$k$个$queue$保存每个人的可扩展的城堡,模拟扩展即可,$s_i$可以每次扩展一格,扩展$s_i$次来解决。复杂度$O(nm)$

卡点:

C++ Code:

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <queue>
#define maxn 1005
#define maxk 10
const int D[2][4] = {{1, 0, -1, 0}, {0, 1, 0, -1}}; struct Point {
int x, y;
Point() { }
Point(int __x, int __y) : x(__x), y(__y) { }
} ;
std::queue<Point> q[maxk]; bool used[maxn][maxn], Continue[maxk];
int n, m, k, len[maxk], ans[maxk]; inline bool over_range(int x, int y) {
return x < 1 || x > n || y < 1 || y > m || used[x][y];
} int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < k; ++i) scanf("%d", len + i);
for (int i = 1; i <= n; ++i) {
static char s[maxn];
scanf("%s", s + 1);
for (int j = 1; j <= m; ++j) if (s[j] != '.') {
used[i][j] = true;
if (isdigit(s[j])) {
int pos = (s[j] & 15) - 1;
++ans[pos];
q[pos].push(Point(i, j));
}
}
}
for (int now = 0, num = k; num; now += 1 - k, now += now >> 31 & k) {
static std::queue<Point> Q;
std::queue<Point> &q = ::q[now];
for (int Tim = len[now]; Tim; --Tim) {
if (q.empty()) {
num -= !Continue[now];
Continue[now] = true;
break;
}
while (!q.empty()) {
Point u = q.front(); q.pop();
for (int i = 0, x, y; i < 4; ++i) {
x = u.x + D[0][i], y = u.y + D[1][i];
if (!over_range(x, y)) {
++ans[now];
used[x][y] = true;
Q.push(Point(x, y));
}
}
}
std::swap(q, Q);
}
}
for (int i = 0; i < k; ++i) printf("%d ", ans[i]); puts("");
return 0;
}

  

[CF1105D]Kilani and the Game的更多相关文章

  1. D. Kilani and the Game 解析(裸BFS、實作)

    Codeforce 1105 D. Kilani and the Game 解析(裸BFS.實作) 今天我們來看看CF1105D 題目連結 題目 給一個\(n\times m\)的地圖,地圖上有幾種格 ...

  2. Kilani and the Game-扩散形式的搜索

    Kilani and the Game 思路:这种扩散走法的并且有速度.我们需要一层一层的入队, 而且 根据题目要求 按编号处理 例如q1队列中有 1 1 1 2 2 2 2 3 3 3 3 3 3 ...

  3. Kilani and the Game CodeForces - 1105D (bfs)

    Kilani is playing a game with his friends. This game can be represented as a grid of size n×mn×m, wh ...

  4. Kilani and the Game-吉拉尼的游戏 CodeForce#1105d 模拟 搜索

    题目链接:Kilani and the Game 题目原文 Kilani is playing a game with his friends. This game can be represente ...

  5. Codeforces H. Kilani and the Game(多源BFS)

    题目描述: Kilani and the Game time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  6. Codeforces 1105D Kilani and the Game【BFS】

    <题目链接> 题目大意: 每个玩家控制一个颜色去扩张,每个颜色的扩张有自己的速度,一个颜色跑完再跑下一种颜色.在所有颜色不能在继续扩张的时候停止游戏.询问此时各种颜色的数量. 解题分析: ...

  7. D. Kilani and the Game(多源BFS)

    题目来源:http://codeforces.com/contest/1105/problem/D 题意:编号为1-k的点在一张n*m的表格中依次扩散,每个结点有各自的扩散速度且只可以往上下左右四个方 ...

  8. Kilani and the Game CodeForces - 1105D (bfs)

    沙茶bfs打了2小时... queue入队量太大了, 放函数里直接T了, 改成全局46ms #include <iostream> #include <algorithm> # ...

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

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

随机推荐

  1. MSP430的CAN通信发送

    1. 电路图如下,RE是接收使能,DE是发送使能,看图的话,这个CAN只支持半双工 2. 使用MSP430F149,以下代码只有发送,其实用的是串口 #include <msp430x14x.h ...

  2. Angular开发者手册重点翻译之指令(一)

    创建自定义的指令 这个文章将解释什么需要在自己的angularjs应用中创建自己的指令,以及如何实现它. 什么是指令 在高的层面上讲,指令是DOM元素中的标记(例如一个属性,一个节点名,注释或者CSS ...

  3. this指向问题(箭头函数没有this)

    全局环境下,指向windows console.log(this.document === document); // true 函数上下文调用 function f1(){ return this; ...

  4. [Ubuntu] <uptime>命令

    uptime 命令 就是查看系统启动时间的,前几个大家应该都很熟悉:当前时间.系统启动时间.正在登陆的用户数 最后的三个数字,分别代表过去 1分钟  5分钟  15分钟  的平均负载(Load Ave ...

  5. 二维DCT变换

    DCT(Discrete Consine Transform),又叫离散余弦变换,它的第二种类型,经常用于信号和图像数据的压缩.经过DCT变换后的数据能量非常集中,一般只有左上角的数值是非零的,也就是 ...

  6. HP Vitrual Connect 配置快速参考

    使用任意浏览器,在地址栏输入VC的管理地址(如果不知道VC的管理地址请从OA中进入) 输入用户名和密码登入VC,验证成功后将进入VM的配置向导 点击"Next"继续,将先进行Dom ...

  7. 剑指 Offer——和为 S 的连续正数序列

    1. 题目 2. 解答 定义两个指针,刚开始分别指向 1 和 2,求出位于这两个指针之间的元素和.如果和大于 S,前面的指针向后移直到和不大于 S 为止:反之,如果和等于 S,则此时两个指针之间的元素 ...

  8. Paper Reading - Deep Visual-Semantic Alignments for Generating Image Descriptions ( CVPR 2015 )

    Link of the Paper: https://arxiv.org/abs/1412.2306 Main Points: An Alignment Model: Convolutional Ne ...

  9. cs231n学习笔记(一)计算机视觉及其发展史

    在网易云课堂上学习计算机视觉经典课程cs231n,觉得有必要做个笔记,因为自己的记性比较差,留待以后查看. 每一堂课都对应一个学习笔记,下面就开始第一堂课. 这堂课主要是回顾了计算机视觉的起源及其后来 ...

  10. PayPal接洽苹果 欲承接手机支付外包

    不久前,<华尔街日报>等媒体报道,苹果正计划利用iTunes内部支付功能,推出第三方手机支付服务.美国科技 新闻网站Recode1月30日引述消息人士称,移动支付领军厂商PayPal,目前 ...