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, 问按 ...
随机推荐
- 20165207 Exp3 免杀原理与实践
Exp3 免杀原理与实践 1.实验内容 1.1.使用msf 1.1.1. 确定基准线 首先看kali的ip 直接msfvenom的结果,不加其他的东西: 使用VirusTotal得到的检测这个程序得到 ...
- linux下删除大量文件提示参数过长解决办法
linux下删除大量文件提示参数过长解决办法:在当前目录下rm -rf * 在linux中删除大量文件时,直接用rm会出现:-bash: /bin/rm: 参数列表过长的错误. 这时可以用find命令 ...
- MySQL性能分析和优化
1. EXPLAIN 优化你的 SELECT 查询 2. 当只要一行数据时使用 LIMIT 1 3. 为搜索字段建索引 like %最好放右边 4. 尽可能的使用 NOT NULL 5. 在Join表 ...
- 出现“基础链接已关闭,无法链接到远程服务器"错误的解决办法
一些用户在安装一些软件或是系统做某些修改后,采集器就没无登录或是无法获取到网页.登录或是使用httppostget工具会出现 ”基础链接已关闭,无法链接到远程服务器“的提示.经分析,是系统Socket ...
- 计算概论(A)/基础编程练习1(8题)/3:晶晶赴约会
#include<stdio.h> int main() { int w; scanf("%d", &w); || w==) { printf("%s ...
- MySQL Crash Course #20# Chapter 28. Managing Security
限制用户的操作权限并不是怕有人恶意搞破坏,而是为了减少失误操作的可能性. 详细文档:https://dev.mysql.com/doc/refman/8.0/en/user-account-manag ...
- JAVA第十周《网络编程》学习内容总结
JAVA第十周<网络编程>学习内容总结 学习内容总结 1.初听到网络编程四个字可能会觉得很困难,实际上网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据,把数据发送到指定的位置, ...
- js实现ajax请求
练下手,好久没写ajax var xmlhttp=null;//创建XMLHttprequest function createXMLHttpRequest(){ if(window.ActiveXO ...
- hdu 2222 Keywords Search - Aho-Corasick自动机
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...
- git分支 远程协作
创建文件mkdir ### cd ### git init 初始化 git config global user.name “username” git config global user.emia ...