[CSU1806]Toll
题目:Toll
传送门:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1806
题目简述:给定n个点m条有向边的有向图,每条边的花费是$b_i * t +d_i$,设f(t)表示给定t的时候1-n的最小花费,求:${\frac{\int_0^T{f(t)dt}}{T}}$
分析:
(1)f(t)可用最短路求出来。
(2)积分值可用自适应辛普森积分法计算。
注意:有向图!
代码:
#include <cstdio>
#include <cstring>
const int N=,QN=,M=;
const double EPS=1e-,INF=1e9;
int n,m;
int size,fi[N];
struct Edge{int to,next;double c,d;}e[M];
void Gadd(int x,int y,double c,double d){
e[++size].to=y;e[size].c=c;e[size].d=d;e[size].next=fi[x];fi[x]=size;
}
int q[N+];double dis[N];bool use[N];
double F(double x){
for(int i=;i<=n;++i)dis[i]=INF;
int h=,t=;dis[q[t]=]=;
for(int v;h!=t;){
if((++h)==QN)h=;use[v=q[h]]=false;
for(int i=fi[v],u;i;i=e[i].next){
u=e[i].to;
if(dis[v]+e[i].c*x+e[i].d<dis[u]){
dis[u]=dis[v]+e[i].c*x+e[i].d;
if(use[u])continue;
if((++t)==QN)t=;use[q[t]=u]=true;
}
}
}
return dis[n];
}
double Simpson(double l,double r){
return (r-l)*(F(l)+*F((l+r)/)+F(r))/;
}
double Abs(double x){return x<?-x:x;}
double Integral(double l,double r,double S){
double mid=(l+r)/;
double A=Simpson(l,mid);
double B=Simpson(mid,r);
if(Abs(A+B-S)<EPS)
return S;else return Integral(l,mid,A)+Integral(mid,r,B);
}
int main(){
for(double T,ans;~scanf("%d%d%lf",&n,&m,&T);){
size=;memset(fi,,sizeof fi);
for(int i=,a,b,c,d;i<=m;++i){
scanf("%d%d%d%d",&a,&b,&c,&d);
Gadd(a,b,(double)c,(double)d);
}
ans=Integral(,T,Simpson(,T))/T;
printf("%.8f\n",ans);
}
return ;
}
[CSU1806]Toll的更多相关文章
- Codeforces Gym 100425D D - Toll Road 找规律
D - Toll RoadTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- UVA 10537 - The Toll! Revisited(dijstra扩张)
UVA 10537 - The Toll! Revisited option=com_onlinejudge&Itemid=8&page=show_problem&catego ...
- UVA10537 Toll! Revisited
difkstra + 路径输出 The Toll! Revisited Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...
- 1774: [Usaco2009 Dec]Toll 过路费
1774: [Usaco2009 Dec]Toll 过路费 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 263 Solved: 154[Submit ...
- Luogu P2966 [USACO09DEC]牛收费路径Cow Toll Paths
题目描述 Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has ...
- BZOJ_1774_[Usaco2009 Dec]Toll 过路费_floyd
BZOJ_1774_[Usaco2009 Dec]Toll 过路费_floyd 题意: 跟所有人一样,农夫约翰以着宁教我负天下牛,休叫天下牛负我的伟大精神,日日夜夜苦思生 财之道.为了发财,他设置了一 ...
- uva 10537 Toll! Revisited(优先队列优化dijstra及变形)
Toll! Revisited 大致题意:有两种节点,一种是大写字母,一种是小写字母. 首先输入m条边.当经过小写字母时须要付一单位的过路费.当经过大写字母时,要付当前財务的1/20做过路费. 问在起 ...
- [USACO09DEC] Cow Toll Paths
https://www.luogu.org/problem/show?pid=2966 题目描述 Like everyone else, FJ is always thinking up ways t ...
- P2966 [USACO09DEC]牛收费路径Cow Toll Paths
P2966 [USACO09DEC]牛收费路径Cow Toll Paths 题目描述 Like everyone else, FJ is always thinking up ways to incr ...
随机推荐
- 5期-Metasploitable3专题课程
metasploitable2基于ubantu的渗透演练环境.Rapid7官方长时间未更新,导致跟不上当前的节奏.metasploitable3出世. metasploitable2配合metaspl ...
- Parentheses Sequence微软编程笔试
描述 You are given a sequence S of parentheses. You are asked to insert into S as few parentheses as p ...
- vim-tabe多标签切换
vim-tabe多标签切换 本文转载自https://www.cnblogs.com/liqiu/archive/2013/03/26/2981949.html 1.新建标签页 使用:tabe命令和文 ...
- python的包
1. 无论是import形式还是from...import形式,凡是在导入语句中(而不是在使用时)遇到带点的,都要第一时间提高警觉:这是关于包才有的导入语法 2. 包是目录级的(文件夹级),文件夹是用 ...
- CCNA 之 二 OSI七层模型
OSI网际互联 OSI的概念 英文全称Open System Interconnect 开放系统互联参数模型,是由ISO国际标准化组织 定义的.它是个灵活的.稳健的和可互操作的模型,并不是协议,使用来 ...
- Java连接SQL Server:jTDS驱动兼容性问题
Java连接SQL Server 2000数据库时,有两种方法: (1)通过Microsoft的JDBC驱动连接.此JDBC驱动共有三个文件,分别是mssqlserver.jar.msutil.jar ...
- jvm(4) 对象创建
1.对象的创建过程: 1.new 类名 2.根据new的参数在常量池中定位一个类的符号的引用. 3.如果没找到这个符号的引用,说明类还没有被加载.则进行类的加载,解析和初始化 4.虚拟机为对象分配内存 ...
- .net core 简单集成JWT报No authenticationScheme was specified, and there was no DefaultChallengeScheme found错误
#region JWT 认证 services .AddAuthentication(JwtBearerDefaults.AuthenticationScheme) //.AddCustomAuth( ...
- JS中的reduce函数
海纳百川,有容乃大 定义: reduce()方法接受一个函数作为累加器,数组中的每个值(从左向右)开始缩减,最终计算为一个值.对空数组是不会执行回调函数的. 案例: 计算数组总和: var num = ...
- JAVA-第一期学习(上)
前言 果然,flag这个东西不能随便立,在我立志要学习java的第4天,我终于打开了我的eclipse.. 本章学习的内容是红框,第一期学习.真好,7月份需要学习完的东西,现在连helloworld还 ...