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. python 比较数字大小按从大到小输出

    主要用到的python 的知识点 1:   内置函数max 2:     列表的操作 3:   while 循环 4 :  错误处理 代码如下: #!/usr/bin/python #coding=u ...

  2. CentOS7 安装 MySQL 5.7

    wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz yum -y ...

  3. 从A小程序跳转到B小程序

    从A小程序跳转到B小程序: A小程序 wxml: <navigator target="miniProgram" open-type="navigate" ...

  4. numpy学习笔记 - numpy常用函数、向量化操作及基本数学统计方法

    # -*- coding: utf-8 -*-"""主要记录代码,相关说明采用注释形势,供日常总结.查阅使用,不定时更新.Created on Fri Aug 24 19 ...

  5. 【codeforces 314C】Sereja and Subsequences

    [题目链接]:http://codeforces.com/problemset/problem/314/C [题意] 让你从n个元素的数组中选出所有的不同的非递减子数列; 然后计算比这个子数列小的和它 ...

  6. Unix发展史

    简述 了解过去,我们才能知其然,更知所以然.总结过去,我们才会知道明天该何去何从.在时间的滚轮中,许许多多的东西就像流星一样一闪而逝,而有些东西却能经受着时间的考验散发着经久的魅力,让人津津乐道.流传 ...

  7. Qt之自定义布局管理器(QBorderLayout)

    简述 QBorderLayout,顾名思义-边框布局,实现了排列子控件包围中央区域的布局. 具体实现要求不再赘述,请参考前几节内容. 简述 实现 效果 源码 使用 实现 QBorderLayout主要 ...

  8. linux搜索文件过程

    1.文件里的数据是放在磁盘的数据区中的,而一个文件名称则是通过相应的i节点与这些磁盘块联系起来.这些盘块的号码就存放在i节点的逻辑块数组i_zone[]中.在文件系统的一个文件夹中,当中全部文件名称信 ...

  9. 大浪淘沙,JSP终将死去

    首先讲明,我不是标题党. 这纯属我个人的意见.勿喷. 先来讲讲JSP是怎么出现的吧. 在早期的WEB中,JS.CSS远未成熟,技术慷慨向并不明白!因为前端语言的匮乏.各家大公司都推出基于后端的模板语言 ...

  10. Hibernate是怎么工作的——Hibernate的工作流程

    举个简单的样例说明: 1.Base.java package cn.flymouse.hibernate; import java.util.Date; import org.hibernate.Qu ...