Kilani and the Game CodeForces - 1105D (bfs)
沙茶bfs打了2小时... queue入队量太大了, 放函数里直接T了, 改成全局46ms
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head const int N= 1e3+10;
int n, m, p;
struct _ {
int x,y,v;
};
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
queue<_> q[20], Q;
int a[20], vis[N][N], ans[20];
char s[N][N]; int expand(int id) {
while (!q[id].empty()) {
_ t = q[id].front();q[id].pop();
t.v = a[id];
Q.push(t);
}
int ok = 0;
while (!Q.empty()) {
_ t = Q.front();Q.pop();
if (!t.v) {
q[id].push(t);
continue;
}
REP(i,0,3) {
int x=t.x+dx[i],y=t.y+dy[i],v=t.v-1;
if (x<=0||y<=0||x>n||y>m||vis[x][y]||s[x][y]=='#') continue;
ok = 1;
vis[x][y] = id;
Q.push({x,y,v});
}
}
return ok;
} int main() {
scanf("%d%d%d", &n, &m, &p);
REP(i,1,p) scanf("%d", a+i);
REP(i,1,n) scanf("%s", s[i]+1);
REP(i,1,n) REP(j,1,m) {
if (isdigit(s[i][j])) {
int ii = s[i][j]-'0';
vis[i][j]=ii;
q[ii].push({i,j,a[i]});
}
}
while (1) {
int ok = 0;
REP(i,1,p) ok |= expand(i);
if (!ok) break;
}
REP(i,1,n) REP(j,1,m) ++ans[vis[i][j]];
REP(i,1,p) printf("%d ",ans[i]);hr;
}
Kilani and the Game CodeForces - 1105D (bfs)的更多相关文章
- 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 ...
- Codeforces 1105D (BFS)
题面 传送门 分析 考虑BFS while(棋盘没有满){ for 玩家 p{ 对p进行BFS,走s[p]步 } } 对于每个玩家p BFS的时候如果到了格子(x,y),就把\(vis[x][y]\) ...
- D. Kilani and the Game 解析(裸BFS、實作)
Codeforce 1105 D. Kilani and the Game 解析(裸BFS.實作) 今天我們來看看CF1105D 題目連結 題目 給一個\(n\times m\)的地圖,地圖上有幾種格 ...
- Codeforces 1105D Kilani and the Game【BFS】
<题目链接> 题目大意: 每个玩家控制一个颜色去扩张,每个颜色的扩张有自己的速度,一个颜色跑完再跑下一种颜色.在所有颜色不能在继续扩张的时候停止游戏.询问此时各种颜色的数量. 解题分析: ...
- Codeforces 1105D(Kilani and the Game,双队列bfs)
AC代码: #include<bits/stdc++.h> #define ll long long #define endl '\n' #define mem(a,b) memset(a ...
- CodeForces - 1105D Kilani and the Game(多源BFS+暴力)
题目: 给出一张游戏地图和每个玩家的位置,每次能移动的步数.p个玩家轮流移动占领地图中的格子(当格子已经被占领时就不能在占领了)在每个玩家都不能移动时游戏结束. 问在游戏结束后,每个玩家占领的格子的数 ...
- Arthur and Walls CodeForces - 525D (bfs)
大意: 给定格点图, 每个'.'的连通块会扩散为矩形, 求最后图案. 一开始想得是直接并查集合并然后差分, 但实际上是不对的, 这个数据就可以hack掉. 3 3 **. .** ... 正解是bfs ...
- Police Stations CodeForces - 796D (bfs)
大意: 给定树, 有k个黑点, 初始满足条件:所有点到最近黑点距离不超过d, 求最多删除多少条边后, 使得原图仍满足条件. 所有黑点开始bfs, 贪心删边. #include <iostream ...
- Three Pieces CodeForces - 1065D (BFS)
链接 大意: n*n棋盘, 每个格子写有数字, 各不相同, 范围[1,n*n], 初始在数字1的位置, 可以操纵knight,bishop,rook三种棋子, 每走一步花费1, 交换棋子花费1, 问按 ...
随机推荐
- Azkaban 入门
需求 实际当中经常有这些场景:每天有一个大任务,这个大任务可以分成A,B,C,D四个小任务,A,B任务之间没有依赖关系,C任务依赖A,B任务的结 果,D任务依赖C任务的结果.一般的做法是,开两个终端同 ...
- 百度地图api通过地址显示地图,白名单
百度地图api通过地址显示地图,白名单 http://developer.baidu.com/map/jsdemo.htm#i7_1?qq-pf-to=pcqq.c2c---------------- ...
- Rest风格(占位符)的映射
- 含有虚函数的类sizeof大小
#include <iostream> using namespace std; class Base1{ virtual void fun1(){} virtual void fun11 ...
- Linux笔记 #07# 搭建机器学习环境
环境: Debian 8.8 64位, 同样适用 win10 基本步骤: 安装 Python 安装必要的库 测试 一.安装 Python 延续之前的 搭建 Python 环境 选取折中版本 Pytho ...
- Linux学习笔记之Linux Centos关闭防火墙
# Centos6.x /etc/init.d/iptables stop chkconfig iptables off sed -i 's/SELINUX=enforcing/SELINUX=dis ...
- bzoj2982: combination(Lucas定理)
Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...
- HTML JavaScript 基础学习
HTML 中肯定会用到 JavaScript 的知识点,会点 JavaScript 的基础知识不会吃亏,其实打算去买JavaScript的教程去专门学习一下,但是交给我的时间不多了,记录一点,能会一点 ...
- 基于qml创建最简单的图像处理程序(1)-基于qml创建界面
<基于qml创建最简单的图像处理程序>系列课程及配套代码基于qml创建最简单的图像处理程序(1)-基于qml创建界面http://www.cnblogs.com/jsxyhelu/p/83 ...
- 过滤Windows文件名中的非法字符
转载:http://blog.csdn.net/infoworld/article/details/42033097 场景: 1. 通常生成文件时需要一个文件名,而生成文件名的方式可能是通过用户输入的 ...