Gym - 100685F Flood BFS
题意:n个水池之间流水,溢出多少流出多少,多个流出通道的话平均分配,给你每个水池中的水量和容量,问到最后目标水池中水量。
思路:直接用队列扩展,不过这里有一个优化,就是统计一下每个点的入度,只有对一个点访问次数达到入度次了,再将其加入队尾,这样就保证了对每个点只操作一次,不然WA、TLE各种错
#pragma comment(linker, "/STACK:1000000000")
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define LL long long
#define INF 0x3f3f3f3f
#define MAXN 100005
#define MAXK 100005
#define eps 1e-8
using namespace std;
struct Node{
double m, now;
};
Node p[MAXK];
int cnt[MAXK];
vector<int> G[MAXK];
queue<int> Q;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // OPEN_FILE
int n, k;
scanf("%d%d", &n, &k);
for(int i = ; i <= n; i++){
scanf("%lf%lf", &p[i].m, &p[i].now);
//p[i].pos = i;
}
int x, y, z;
//double y;
memset(cnt, , sizeof(cnt));
for(int i = ; i <= k; i++){
scanf("%d%d", &x, &z);
G[x].push_back(z);
cnt[z]++;
}
scanf("%d%d%d", &x, &y, &z);
// int head = 1, tail = 1;
p[x].now += y;
Q.push(x);
//vis[x] = true;
//double ans = p[z].now;
//int cnt = 0;
while(!Q.empty()){
//cnt++;
int pos = Q.front();
Q.pop();
Node q = p[pos];
if(q.now <= q.m) continue;
p[pos].now = p[pos].m;
if(G[pos].size() == ) continue;
double u = (q.now - q.m) / G[pos].size();
for(int i = ; i < G[pos].size(); i++){
//if(vis[G[q.pos][i]]) continue;
p[G[pos][i]].now += u;
//tail++;
cnt[G[pos][i]]--;
if(cnt[G[pos][i]] == ){
Q.push(G[pos][i]);
}
}
}
printf("%.6lf\n", p[z].now);
}
Gym - 100685F Flood BFS的更多相关文章
- codeforce Gym 100685F Flood (topo排序)
如果直接模拟水向周围流会TLE,因为某些个结点被重复扩展了多次, 科学做法是topo排序,每次只把入度为0的点放入队列,这样就严格保证了每个结点只被扩展一次. #include<bits/std ...
- Codeforces gym 100685 F. Flood bfs
F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Desc ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- Codeforces Gym 100187E E. Two Labyrinths bfs
E. Two Labyrinths Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/prob ...
- Gym 100952F&&2015 HIAST Collegiate Programming Contest F. Contestants Ranking【BFS+STL乱搞(map+vector)+优先队列】
F. Contestants Ranking time limit per test:1 second memory limit per test:24 megabytes input:standar ...
- Gym 101617J Treasure Map(bfs暴力)
http://codeforces.com/gym/101617/attachments 题意:给出一个图,每个顶点代表一个金矿,每个金矿有g和d两个值,g代表金矿初始的金子量,d是该金矿每天的金子量 ...
- Gym - 100971J (思维+简单bfs)
题目链接:http://codeforces.com/gym/100971/problem/J J. Robots at Warehouse time limit per test 2.0 s mem ...
- [LeetCode] 733. Flood Fill_Easy tag: BFS
An image is represented by a 2-D array of integers, each integer representing the pixel value of the ...
- Gym - 101147E E. Jumping —— bfs
题目链接:http://codeforces.com/gym/101147/problem/E 题意:当人在第i个商店时,他可以向左或向右跳di段距离到达另一个商店(在范围之内),一个商店为一段距离. ...
随机推荐
- 洛谷—— P2896 [USACO08FEB]一起吃饭Eating Together
https://www.luogu.org/problem/show?pid=2896 题目描述 The cows are so very silly about their dinner partn ...
- code vs 1216 跳马问题
1216 跳马问题 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 题目 输入描述 Input Descri ...
- Qt之QDesktopServices
简述 QDesktopServices类提供的函数用于访问常见的桌面服务. 许多桌面环境都会提供一系列服务,可以通过应用程序来执行常见任务,如:以用户应用程序首选项的方式,打开一个网页. 此类包含为服 ...
- new 对象和Class的getInstance()方法的差别?
创建对象时的差别 1.new 对象包含2步, 1)载入类: 2)而且实例化. 2.Class的对象.getInstance(),只不过实例化. 也就是说.在运行 Class的对象.getInstanc ...
- Android蓝牙技术Bluetooth使用流程(具体解释)
一:蓝牙设备之间的通信主要包含了四个步骤 设置蓝牙设备 寻找局域网内可能或者匹配的设备 连接设备 设备之间的传输数据 二:详细编程实现 1. 启动蓝牙功能 首先通过调用静态方法getDefaultAd ...
- RvmTranslator7.1
RvmTranslator7.1 eryar@163.com RvmTranslator can translate the RVM file exported by AVEVA Plant(PDMS ...
- RvmTranslator7.0-OBJ
RvmTranslator7.0-OBJ eryar@163.com RvmTranslator can translate the RVM file exported by AVEVA Plant( ...
- java匿名内部类的使用注意事项
1.首先匿名内部类要继承自抽象基类或者实现基类接口 like this abstract class Seed{ int cnt; public Seed(int x){ cnt=x; } abstr ...
- CSDN博客2014年4月24日清理缓存
亲爱的CSDN博主们.我们将于今天(2014年4月24日)对CSDN博客频道缓存进行清理,假设您登录后发现自己的文章总数.积分.评论数.訪问数出现异常,请不要慌张.您的数据并没有丢失.将会在缓存清理完 ...
- 远程登录工具 —— filezilla(FTP vs. SFTP)、xshell、secureCRT
filezilla:是一个免费开源的 FTP 软件,分为客户端版本和服务器版本,具备所有的 FTP 软件功能. 支持的协议:FTP & SFTP(Secure File Transfer Pr ...