题目大意:给出一个$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. WordPress用户导入Drupal7并登录

    用户导入比较简单.使用Feeds模块中的Feeds Import工具就行. 不过有个不好地方的,导入前密码是明文,导入后该模块会自动转换为Drupal加密后的密码. 这需要导入后原wp的用户也能登录d ...

  2. Yii2.0 高级模版编写使用自定义组件(component)

    翻译自:http://www.yiiframework.com/wiki/760/yii-2-0-write-use-a-custom-component-in-yii2-0-advanced-tem ...

  3. MVC捕获数据保存时的具体字段验证错误代码

    ////捕获验证错误代码 //try //{ // // 调试写数据库 //} //catch (DbEntityValidationException dbEx) //{ //}

  4. 前端--javaScript之简单介绍

    一.javaScript(以下简称js)的历史 1992年Nombas开发出C-minus-minus(C--)的嵌入式脚本语言(最初绑定在CEnvi软件中).后将其改名ScriptEase.(客户端 ...

  5. 学习笔记之windows 网络编程

    WinSock2.h编程接口笔记在Qtcreater中使用系统默认的库只需要在.pro文件中添加 LIBS += -lws2_32 添加头文件#include <WinSock2.h *初始化套 ...

  6. 牛客网暑期ACM多校训练营(第四场):A Ternary String(欧拉降幂)

    链接:牛客网暑期ACM多校训练营(第四场):A Ternary String 题意:给出一段数列 s,只包含 0.1.2 三种数.每秒在每个 2 后面会插入一个 1 ,每个 1 后面会插入一个 0,之 ...

  7. 《Cocos2d-x游戏开发实战精解》学习笔记3--在Cocos2d-x中播放声音

    <Cocos2d-x游戏开发实战精解>学习笔记1--在Cocos2d中显示图像 <Cocos2d-x游戏开发实战精解>学习笔记2--在Cocos2d-x中显示一行文字 之前的内 ...

  8. Paper Reading - Im2Text: Describing Images Using 1 Million Captioned Photographs ( NIPS 2011 )

    Link of the Paper: http://papers.nips.cc/paper/4470-im2text-describing-images-using-1-million-captio ...

  9. mysql group by 取第一条

    select * from table where id in (select max(id) from table group by sku) 说明:id是自增序列,sku是表中的一个字段

  10. Amazon 成功的秘訣是…

    從任何的標準去看,今日的 Amazon,都是一家超級成功的企業 — 它的線上書城和其他 B2C 電子商務業務,全球第一,年營業額超過 200 億美金.它的 AWS (Amazon Web Servic ...