题目: 给出一张游戏地图和每个玩家的位置,每次能移动的步数.p个玩家轮流移动占领地图中的格子(当格子已经被占领时就不能在占领了)在每个玩家都不能移动时游戏结束. 问在游戏结束后,每个玩家占领的格子的数目. 思路: 当时做的时候,并没有思路,借鉴了大佬的……Orz 对每一个玩家分配一个队列,这个队列中只保存移动时最后一步的位置.如果在一个循环中p个玩家都没有能够成功移动的,就说明游戏结束了. 然后遍历一下地图,统计一下每个玩家占领的格子就ok了. 代码: #include <bits/stdc++…
AC代码: #include<bits/stdc++.h> #define ll long long #define endl '\n' #define mem(a,b) memset(a,b,sizeof(a)) #define IO ios::sync_with_stdio(false);cin.tie(0); using namespace std; const int INF=0x3f3f3f3f; const ll inf=0x3f3f3f3f3f3f3f3f; ; ; struct…
<题目链接> 题目大意: 每个玩家控制一个颜色去扩张,每个颜色的扩张有自己的速度,一个颜色跑完再跑下一种颜色.在所有颜色不能在继续扩张的时候停止游戏.询问此时各种颜色的数量. 解题分析: 就是用BFS去模拟颜色的扩张,但是需要注意的是,本题需要加一些小的优化,比如,每次只用扩张上一轮BFS新更新的点就行. #include <bits/stdc++.h> using namespace std; #define N int(1e3+7) #define rep(i,s,t) for…
题目:http://codeforces.com/contest/986/problem/A 如果从每个村庄开始bfs找货物,会超时. 发现k较小.那就从货物开始bfs,给村庄赋上dis[ 该货物 ]. 但这样还是n^2.考虑有相同货物的村庄,其实可以一起bfs.就是多源bfs.这样就是n*k的了. 多源bfs就是把一些起始点的dis全赋了初值0,然后都放进队列里,之后正常bfs. #include<iostream> #include<cstdio> #include<cs…
D. Igor In the Museum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem/D Description Igor is in the museum and he wants to see as many pictures as possible. Museum can be represented as a rectangular field of n ×…
题目链接  Problem D 比赛的时候完全想不到 直接对给定的这些点做多源$BFS$,把给定的这些点全都压到队列里,然后一个个做. 最后统计被访问的点的个数即可. #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i) #define dec(i, a, b) for (int i(a); i >= (b); --i) #define MP…
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2252 又没能自己想出来... 一直在想如何从每个1开始广搜更新答案,再剪剪枝,什么遇到1就不走了... 然而实际上直接多源bfs,从所有1一起开始,因为只需要找到0碰到的第一个1即可: 这样搜一遍就可以,复杂度很美. 代码如下: #include<iostream> #include<cstdio> #include<cstring> #include<al…
Codeforces Round #599 (Div. 2) D. 0-1 MST Description Ujan has a lot of useless stuff in his drawers, a considerable part of which are his math notebooks: it is time to sort them out. This time he found an old dusty graph theory notebook with a descr…
Codeforce 1105 D. Kilani and the Game 解析(裸BFS.實作) 今天我們來看看CF1105D 題目連結 題目 給一個\(n\times m\)的地圖,地圖上有幾種格子:空地.路障.某個玩家的某些城堡.(可能有\(1\le p\le9\)個玩家) 給定一開始每個玩家至少有一個城堡,玩家照順序移動,每個玩家有自己的移動步數,求最後每個玩家能有幾個城堡. 前言 寫這題一直TLE,搞了好幾個小時才發現如果每次BFS都宣告一個新的queue,那麼可能會因為allocat…
Kilani is playing a game with his friends. This game can be represented as a grid of size n×mn×m, where each cell is either empty or blocked, and every player has one or more castles in some cells (there are no two castles in one cell). The game is p…