Gym - 100187E E - Two Labyrinths —— bfs】的更多相关文章

E. Two Labyrinths Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/E Description A labyrinth is the rectangular grid, each of the cells of which is either free or wall, and it's possible to move only between free…
题目链接:http://codeforces.com/gym/100187/problem/E 题解:一开始做的时候是将两幅图合并,然后直接bfs看是否能到达终点.但这种做法的错的,因为走出来的路对于两幅图来说不一定都是最短的.正确做法: 第一步:分别用bfs求出两图的最短路. 第二步:如果最短路长度一样.则将两幅图合并,再bfs,如果能走到终点,且最短路长度仍然等于未合并前的长度,则YES: 否则NO. 学习之处: 求两个或多个事物所共有的东西,其实就是求交集. 代码如下: #include<…
题意:问两个迷宫是否存在公共最短路. 题解:两个反向bfs建立层次图,一遍正向bfs寻找公共最短路 #include<cstdio> #include<cstring> #include<queue> using namespace std; +; int d1[maxn][maxn]; int d2[maxn][maxn]; char g1[maxn][maxn]; char g2[maxn][maxn]; int n,m; struct node{ int x,y;…
Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u  Practice  Description standard input/output Ayutthaya was one of the first kingdoms in Thailand, spanning since its foundation in 1350 to…
http://codeforces.com/gym/101617/attachments 题意:给出一个图,每个顶点代表一个金矿,每个金矿有g和d两个值,g代表金矿初始的金子量,d是该金矿每天的金子量会减少d.顶点与顶点之间存在边,意思是从一个金矿到另一个金矿需要花费的天数.现在有个人一开始在1金矿,问最多能挖到多少金矿,注意,不能在一个金矿连续挖几天. 思路:bfs求解,但是需要剪枝,用二位数组d[v][day]记录第day天时在v金矿所能获得的最大值. #include<iostream>…
题目链接:http://codeforces.com/gym/100971/problem/J J. Robots at Warehouse time limit per test 2.0 s memory limit per test 256 MB input standard input output standard output Vitaly works at the warehouse. The warehouse can be represented as a grid of n ×…
题目传送门 题目大意:给出一幅海洋的描述,0为海平面,负数即有水,在给出的xy坐标的底部安放抽水机,问最多能有多少水.水往低处流,且八个方向都可以. 思路:bfs,记录到每一个节点有效的最低海平面,然后尝试更新周围的点. 但这道题需要优先队列,有效海平面最低的先出队,否则会TLE. #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<strin…
F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Description We all know that King Triton doesn't like us and therefore shipwrecks, hurricanes and tsunami do happen. But being bored with the same routine…
F. Contestants Ranking time limit per test:1 second memory limit per test:24 megabytes input:standard input output:standard output Ahmad is one of the best students in HIAST, and also a very good problems Solver. In the time you will spend reading th…
题目链接:http://codeforces.com/gym/101147/problem/E 题意:当人在第i个商店时,他可以向左或向右跳di段距离到达另一个商店(在范围之内),一个商店为一段距离.问:对于每一个商店,跳到最后一个商店最少需要跳几次? 题解:题目实际上是求最短距离,而且边权为1,所以可以直接用bfs.由于是求每个点到最后一个点的最短距离,那么可以反向建图,将最后一个点设为起始点,然后向前跑.对于跑不到的点,回到题目上说,实际就是这个商店不能到达最后一个商店. 代码如下: #in…