题目:

给出一张游戏地图和每个玩家的位置,每次能移动的步数。p个玩家轮流移动占领地图中的格子(当格子已经被占领时就不能在占领了)在每个玩家都不能移动时游戏结束。

问在游戏结束后,每个玩家占领的格子的数目。

思路:

当时做的时候,并没有思路,借鉴了大佬的……Orz

对每一个玩家分配一个队列,这个队列中只保存移动时最后一步的位置。如果在一个循环中p个玩家都没有能够成功移动的,就说明游戏结束了。

然后遍历一下地图,统计一下每个玩家占领的格子就ok了。

代码:

#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <iomanip>
#define MOD 998244353
#define MAX 1000000000
#define inf 0x3f3f3f3f
#define FRE() freopen("in.txt","r",stdin)
#define FRO() freopen("out.txt","w",stdout)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = ;
int n,m,p;
int vis[maxn][maxn],s[maxn],ans[maxn];
int dx[]={,,,-};
int dy[]={,-,,};
char mp[maxn][maxn];
struct Node
{
int x,y,t;
};
queue<Node> q1[maxn],q2[maxn]; bool isin(int x,int y)
{
return x>= && x<n && y>= && y<m;
} int MultipleBfs(int id)
{
while(!q2[id].empty())
{
Node now = q2[id].front();
q2[id].pop();
now.t = ;//开始移动时步数都是0的,好好想想……
q1[id].push(now);
} int flag = ;
while(!q1[id].empty())
{
Node now = q1[id].front();
q1[id].pop();
if(now.t == s[id])//记录最外围的格子的位置
{
q2[id].push(now);
continue;
} for(int i=; i<; i++)
{
int tx = now.x+dx[i],ty = now.y+dy[i];
if(isin(tx,ty) && !vis[tx][ty] && mp[tx][ty]!='#')
{
vis[tx][ty] = id;
q1[id].push(Node{tx,ty,now.t+});
flag++;//标记这个玩家有没有移动
}
}
}
if(flag>) return ;
else return ;
} int main()
{
//FRE();
while(scanf("%d%d%d",&n,&m,&p) != EOF)
{
memset(ans,,sizeof(ans));
memset(vis,,sizeof(vis));
for(int i=; i<=p; i++) scanf("%d",&s[i]);
for(int i=; i<n; i++)
{
scanf("%s",mp[i]);
for(int j=; j<m; j++)
{
if(isdigit(mp[i][j]))
{
int x = mp[i][j] - '';
vis[i][j] = x;//对每个玩家的位置进行预先标记
q2[x].push(Node{i,j,});//压入队列
}
}
} while(true)
{
int flag = ;
for(int i=; i<=p; i++)
{
flag += MultipleBfs(i);
}
if(!flag) break;//如果没有玩家能够移动就退出
} for(int i=; i<n; i++)//统计每个玩家的格子
{
for(int j=; j<m; j++)
{
//printf("%d ",vis[i][j]);
ans[vis[i][j]]++;
}
//printf("\n");
} for(int i=; i<=p; i++)
{
if(i!=) printf(" ");
printf("%d",ans[i]);
}
printf("\n");
}
return ;
}

CodeForces - 1105D Kilani and the Game(多源BFS+暴力)的更多相关文章

  1. 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 ...

  2. Codeforces 1105D Kilani and the Game【BFS】

    <题目链接> 题目大意: 每个玩家控制一个颜色去扩张,每个颜色的扩张有自己的速度,一个颜色跑完再跑下一种颜色.在所有颜色不能在继续扩张的时候停止游戏.询问此时各种颜色的数量. 解题分析: ...

  3. CF 986A Fair——多源bfs

    题目:http://codeforces.com/contest/986/problem/A 如果从每个村庄开始bfs找货物,会超时. 发现k较小.那就从货物开始bfs,给村庄赋上dis[ 该货物 ] ...

  4. Educational Codeforces Round 1 D. Igor In the Museum bfs 并查集

    D. Igor In the Museum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598 ...

  5. 牛客网 牛客练习赛7 D. 珂朵莉的无向图(多源BFS)

    题目链接  Problem D 比赛的时候完全想不到 直接对给定的这些点做多源$BFS$,把给定的这些点全都压到队列里,然后一个个做. 最后统计被访问的点的个数即可. #include <bit ...

  6. bzoj 2252 [ 2010 Beijing wc ] 矩阵距离 —— 多源bfs

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2252 又没能自己想出来... 一直在想如何从每个1开始广搜更新答案,再剪剪枝,什么遇到1就不 ...

  7. Codeforces Round #599 (Div. 2) D. 0-1 MST(bfs+set)

    Codeforces Round #599 (Div. 2) D. 0-1 MST Description Ujan has a lot of useless stuff in his drawers ...

  8. D. Kilani and the Game 解析(裸BFS、實作)

    Codeforce 1105 D. Kilani and the Game 解析(裸BFS.實作) 今天我們來看看CF1105D 題目連結 題目 給一個\(n\times m\)的地圖,地圖上有幾種格 ...

  9. 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 ...

随机推荐

  1. Codeforces - 1081C - Colorful Bricks - 简单dp - 组合数学

    https://codeforces.com/problemset/problem/1081/C 这道题是不会的,我只会考虑 $k=0$ 和 $k=1$ 的情况. $k=0$ 就是全部同色, $k=1 ...

  2. bzoj 2588: Spoj 10628. Count on a tree【主席树+倍增】

    算是板子,把值离散化,每个点到跟上做主席树,然后查询的时候主席树上用u+v-lca-fa[lca]的值二分 #include<iostream> #include<cstdio> ...

  3. Mantis优化改造(功能篇)

    共分为两篇,功能篇和技术篇. 时间大约是2016年冬天. 考虑搭一个用于Bug管理和追踪的系统. 综合比较下,选择了小巧的开源工具,Mantis. 在源码基础上,做代码修改,完成了定制版的优化改造. ...

  4. 题解报告:hdu 6441 Find Integer(费马大定理+智慧数)

    Problem Description people in USSS love math very much, and there is a famous math problem .give you ...

  5. 1-1-Java的特点

    Java语言平台 JavaSE(Java Platform Standard Edition)标准版 以前叫做J2SE,5.0版本后改名叫做JAVASE,主要用于桌面应用程序的开发,该技术体系是后两者 ...

  6. Myisamchk使用

    Myisam损坏的情况: . 服务器突然断电导致数据文件损坏;强制关机,没有先关闭mysql 服务;mysqld 进程在写表时被杀掉.因为此时mysql可能正在刷新索引. . 磁盘损坏. . 服务器死 ...

  7. linux/centos系统如何使用yum安装vi/vim?

    yum安装vim最简单的命令, yum -y install vim* 然后就可以使用vi命令了. 网上的文章: 要使用vim, 使用yum看了一下,发现有4个 vim-common.i386     ...

  8. qconshanghai2016

    http://2016.qconshanghai.com/schedule 大会日程 2016年10月20日 星期四 07:45 开始签到 09:00 开场致辞 专题 前端技术实践 主题演讲 业务上云 ...

  9. 【C#】将数据库读出的数据转换为DataTable类型集合

    return View(ConverDataReaderToDataTable(reader)); // 静态方法public static DataTable ConverDataReaderToD ...

  10. idea使用Git提交代码时忽略指定文件或文件夹

    简述 使用idea编写代码并使用git作为版本控制器的时候,常常不需要提交配置文件以及一些其他不需要提交的文件,可以使用.ignore插件来在上传的时候忽略一些文件或文件夹. 安装 注意:安装完成之后 ...