Gym - 100685F

题意: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的更多相关文章

  1. codeforce Gym 100685F Flood (topo排序)

    如果直接模拟水向周围流会TLE,因为某些个结点被重复扩展了多次, 科学做法是topo排序,每次只把入度为0的点放入队列,这样就严格保证了每个结点只被扩展一次. #include<bits/std ...

  2. Codeforces gym 100685 F. Flood bfs

    F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Desc ...

  3. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  4. Codeforces Gym 100187E E. Two Labyrinths bfs

    E. Two Labyrinths Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/prob ...

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

  6. Gym 101617J Treasure Map(bfs暴力)

    http://codeforces.com/gym/101617/attachments 题意:给出一个图,每个顶点代表一个金矿,每个金矿有g和d两个值,g代表金矿初始的金子量,d是该金矿每天的金子量 ...

  7. Gym - 100971J (思维+简单bfs)

    题目链接:http://codeforces.com/gym/100971/problem/J J. Robots at Warehouse time limit per test 2.0 s mem ...

  8. [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 ...

  9. Gym - 101147E E. Jumping —— bfs

    题目链接:http://codeforces.com/gym/101147/problem/E 题意:当人在第i个商店时,他可以向左或向右跳di段距离到达另一个商店(在范围之内),一个商店为一段距离. ...

随机推荐

  1. parted 4T磁盘

    parted /dev/vdg mklabel gpt mkpart primary ext4 0% 100%

  2. 紫书 习题 8-21 UVa 1621 (问题分析方法)

    知道是构造法但是想了挺久没有什么思路. 然后去找博客竟然只有一篇!!https://blog.csdn.net/no_name233/article/details/51909300 然后博客里面又说 ...

  3. 紫书 例题8-15 UVa 12174 (滑动窗口)

    这道题就是给你一n长序列, 然后把这个序列按顺序分成很多段, 每段长s(最前面可以小于s, 只有第一段的后半段, 最后面也同样, 只有最后一段的前半段), 然后要求是每一段里面没有重复的数, 问你有几 ...

  4. 洛谷——P2615 神奇的幻方 【Noip2015 day1t1】

    https://www.luogu.org/problem/show?pid=2615 题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之 ...

  5. 不安全的直接对象引用:你的 ASP.NET 应用数据是否安全?

    介绍 作为一个在X94的航空工程师,你的老板要求你从2号楼的工程图中检索出一个特定的专利.不幸的是,进入大楼需要你出示你具有进入大楼的资格的证明,然后你迅速地以徽章的形式出示给了保安.到了十三楼,进入 ...

  6. Mybatis Generator for SQL Server

    Mybatis Generator for SQL Server <?xml version="1.0" encoding="UTF-8" ?> & ...

  7. 【Linux编程】socket编程

    套接字是通信端点的抽象.文件描写叙述符用open函数创建,而套接字描写叙述符用socket函数创建.socket函数原型例如以下: int socket(int domain, int type, i ...

  8. UItableView中的一些方法

    有关UITableView的知识点相对照较简单,一些简单的经常使用的方法有时间在写上: 以下的几个方法假设仅仅是展示UITableView是用不到的,须要对对应的区段进行操作的时候才会用到. 方法例如 ...

  9. dns-sd._udp.<domain>. 域名发现 本质和MDNS同

    DNS Service Discovery is a way of using standard DNS programming interfaces, servers, and packet for ...

  10. SharePoint 第一个网站

    第一个网站 1.建立一个社区门户网站首先要建一个IIS网站,并且把匿名访问勾选上,这样才能真正的访问网站. 创建网站的时候更改自己想要的端口,以便操作 这里更改网站是否启用匿名访问权限.点击是 然后保 ...