[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个人,同时有每个人的扩张次数(我开始以为是直线扩张最大长度..实际是能连 ...
随机推荐
- Win SERVER 2008 许可证激活失败,系统重启问题
服务器系统win server2008 R2 SP1,频繁重启,查看日志 有显示 许可证激活(slui.exe)失败,错误代码如下:0x800401F9 和 Windows 许可证激活失败.错误 0x ...
- Yii2.0 高级模版编写使用自定义组件(component)
翻译自:http://www.yiiframework.com/wiki/760/yii-2-0-write-use-a-custom-component-in-yii2-0-advanced-tem ...
- 简单读取 properties文件
看了网上很多读取的方法,都太过复杂,直接使用下面的方法就可以简单读取 properties文件了 ide使用idea 测试读取成功 import java.util.ResourceBundle; p ...
- angular之$watch() $watchGroup()和$watchCollection()
$watch $watch主要是用来监听一个对象,在对象发生变化时触发某个事件. 用法: $scope.$watch(watchFn,watchAction, deepWatch) 接下来讲一下这几个 ...
- javaweb(二十二)——基于Servlet+JSP+JavaBean开发模式的用户登录注册
一.Servlet+JSP+JavaBean开发模式(MVC)介绍 Servlet+JSP+JavaBean模式(MVC)适合开发复杂的web应用,在这种模式下,servlet负责处理用户请求,jsp ...
- 自己做的一个固定大小对象内存池,效率大概为原始的new/delete的2倍
提升不高,不过好处是可以多次申请小对象,一次释放.(只适应于无动态申请资源的class) vs2012测试情况如下: // CHchFixLenMemPool.h #pragma once #ifnd ...
- Unity初级案例——贪吃蛇
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; ...
- MapReduce和yarn
1.Mapreduce是什么? Mapreduce是一个分布式运算程序的编程框架,是用户开发“基于hadoop的数据分析应用”的核心框架: Mapreduce核心功能是将用户编写的业务逻辑代码和自带默 ...
- Mybatis-Plus的填坑之路 - Lynwood/wunian7yulian
目录 Mybatis-Plus 我来填坑~ 目录 一.简单介绍 官方说明 : 成绩: 最新版本: 开发层面MyBatis-Plus特色 Mybatis-Plus中的Plus 二.MP的特性 三.MP框 ...
- Ubuntu系统下在PyCharm里用virtualenv集成TensorFlow
我的系统环境 Ubuntu 18.04 Python3.6 PyCharm 2018.3.2 community(免费版) Java 1.8 安装前准备 由于众所周知的原因,安装中需要下载大量包,尽量 ...