Gym - 100685F Flood BFS】的更多相关文章

Gym - 100685F 题意:n个水池之间流水,溢出多少流出多少,多个流出通道的话平均分配,给你每个水池中的水量和容量,问到最后目标水池中水量. 思路:直接用队列扩展,不过这里有一个优化,就是统计一下每个点的入度,只有对一个点访问次数达到入度次了,再将其加入队尾,这样就保证了对每个点只操作一次,不然WA.TLE各种错 #pragma comment(linker, "/STACK:1000000000") #include <iostream> #include <…
如果直接模拟水向周围流会TLE,因为某些个结点被重复扩展了多次, 科学做法是topo排序,每次只把入度为0的点放入队列,这样就严格保证了每个结点只被扩展一次. #include<bits/stdc++.h> using namespace std; #define eps 1e-9 #define bug(x) cout<<#x<<'='<<x<<endl; #define Min 1e-7 ; ; struct Ponds { double c…
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…
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…
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…
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/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 ×…
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535). Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor,…
题目链接:http://codeforces.com/gym/101147/problem/E 题意:当人在第i个商店时,他可以向左或向右跳di段距离到达另一个商店(在范围之内),一个商店为一段距离.问:对于每一个商店,跳到最后一个商店最少需要跳几次? 题解:题目实际上是求最短距离,而且边权为1,所以可以直接用bfs.由于是求每个点到最后一个点的最短距离,那么可以反向建图,将最后一个点设为起始点,然后向前跑.对于跑不到的点,回到题目上说,实际就是这个商店不能到达最后一个商店. 代码如下: #in…