[CF1105D]Kilani and the Game
题目大意:给出一个$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的更多相关文章
- D. Kilani and the Game 解析(裸BFS、實作)
Codeforce 1105 D. Kilani and the Game 解析(裸BFS.實作) 今天我們來看看CF1105D 題目連結 題目 給一個\(n\times m\)的地圖,地圖上有幾種格 ...
- Kilani and the Game-扩散形式的搜索
Kilani and the Game 思路:这种扩散走法的并且有速度.我们需要一层一层的入队, 而且 根据题目要求 按编号处理 例如q1队列中有 1 1 1 2 2 2 2 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 ...
- Kilani and the Game-吉拉尼的游戏 CodeForce#1105d 模拟 搜索
题目链接:Kilani and the Game 题目原文 Kilani is playing a game with his friends. This game can be represente ...
- 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 ...
- Codeforces 1105D Kilani and the Game【BFS】
<题目链接> 题目大意: 每个玩家控制一个颜色去扩张,每个颜色的扩张有自己的速度,一个颜色跑完再跑下一种颜色.在所有颜色不能在继续扩张的时候停止游戏.询问此时各种颜色的数量. 解题分析: ...
- D. Kilani and the Game(多源BFS)
题目来源:http://codeforces.com/contest/1105/problem/D 题意:编号为1-k的点在一张n*m的表格中依次扩散,每个结点有各自的扩散速度且只可以往上下左右四个方 ...
- Kilani and the Game CodeForces - 1105D (bfs)
沙茶bfs打了2小时... queue入队量太大了, 放函数里直接T了, 改成全局46ms #include <iostream> #include <algorithm> # ...
- Codeforces Round #533(Div. 2) D.Kilani and the Game
链接:https://codeforces.com/contest/1105/problem/D 题意: 给n*m的地图,最多9个人,同时有每个人的扩张次数(我开始以为是直线扩张最大长度..实际是能连 ...
随机推荐
- OpenStack入门篇(六)之OpenStack环境准备
一.Openstack的概述 Openstack是一个由NASA(美国国家航空航天局)和Rackspace合作研发并发起的,以Apache许可证授权的自由软件和开放源代码项目. Openstack是一 ...
- crontab练习题
Crontab练习题 每周一到周六的凌晨3点20分,运行tar命令对/etc/目录进行存档另存,存储位置为/backups/etc-YYYY-MM-DD.tar.gz 20 3 * * 1-6 /us ...
- 创龙OMAPL138的NMI中断
1. 不可屏蔽中断部分代码,注册中断函数,6748有几个NMI的引脚? void InterruptInit(void) { // 初始化 DSP 中断控制器 IntDSPINTCInit(); // ...
- python3.0 day02 列表、元组 、字典、字符串操作
1.列表.元组操作 列表是我们最以后最常用的数据类型之一,通过列表可以对数据实现最方便的存储.修改等操作,类似于其他语言中的数组. 定义列表 names = ['Lioa',"Tenglan ...
- ABP中module-zero快速集成微信用户认证
https://personball.com/abp/2019/01/01/introduce-abp-module-zero-external-authenticate
- javaweb(十四)——JSP原理
一.什么是JSP? JSP全称是Java Server Pages,它和servle技术一样,都是SUN公司定义的一种用于开发动态web资源的技术. JSP这门技术的最大的特点在于,写jsp就像在写h ...
- 行驶证识别/行驶证OCR识别全方位解析
本文全面解析行驶证OCR识别,包括什么是行驶证OCR识别.如何选择行驶证识别软件.如何操作行驶证识别软件,以及该软件应用的领域等. 一.了解行驶证识别/行驶证OCR识别 行驶证OCR识别技术,也叫行驶 ...
- Vue学习计划基础笔记(一) - vue实例
最近又重新看vue的文档了,计划是别人写的,之前看过一次,没有考虑太多,只考虑看懂能用就好.看完之后写过写demo,现在是零实际项目经验的,所以这一次打算细看,算是官方文档的二次产物吧,但是不是全部直 ...
- 8 个用于业余项目的优秀 Python 库
在 Python/Django 的世界里有这样一个谚语:为语言而来,为社区而留.对绝大多数人来说的确是这样的,但是,还有一件事情使得我们一直停留在 Python 的世界里,不愿离开,那就是我们可以很容 ...
- 【springmvc+mybatis项目实战】杰信商贸-6.重点知识回顾
1.重点知识回顾 Maven1)覆盖仓库文件,实际企业开发,公司会架一个测试服务器,在测试服务器中架私服.我们开发人员的程序,都连接私服.当本地没有项目中要使用的jar,Myeclipse maven ...