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

  1. Codeforces Gym 100425D D - Toll Road 找规律

    D - Toll RoadTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...

  2. UVA 10537 - The Toll! Revisited(dijstra扩张)

    UVA 10537 - The Toll! Revisited option=com_onlinejudge&Itemid=8&page=show_problem&catego ...

  3. UVA10537 Toll! Revisited

    difkstra + 路径输出 The Toll! Revisited Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...

  4. 1774: [Usaco2009 Dec]Toll 过路费

    1774: [Usaco2009 Dec]Toll 过路费 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 263  Solved: 154[Submit ...

  5. Luogu P2966 [USACO09DEC]牛收费路径Cow Toll Paths

    题目描述 Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has ...

  6. BZOJ_1774_[Usaco2009 Dec]Toll 过路费_floyd

    BZOJ_1774_[Usaco2009 Dec]Toll 过路费_floyd 题意: 跟所有人一样,农夫约翰以着宁教我负天下牛,休叫天下牛负我的伟大精神,日日夜夜苦思生 财之道.为了发财,他设置了一 ...

  7. uva 10537 Toll! Revisited(优先队列优化dijstra及变形)

    Toll! Revisited 大致题意:有两种节点,一种是大写字母,一种是小写字母. 首先输入m条边.当经过小写字母时须要付一单位的过路费.当经过大写字母时,要付当前財务的1/20做过路费. 问在起 ...

  8. [USACO09DEC] Cow Toll Paths

    https://www.luogu.org/problem/show?pid=2966 题目描述 Like everyone else, FJ is always thinking up ways t ...

  9. P2966 [USACO09DEC]牛收费路径Cow Toll Paths

    P2966 [USACO09DEC]牛收费路径Cow Toll Paths 题目描述 Like everyone else, FJ is always thinking up ways to incr ...

随机推荐

  1. C++ 测量程序执行时间的办法

    #include <time.h> clock_t start = clock(); //时间起始 /*待测试代码*/ clock_t end = clock(); //时间测试结束 co ...

  2. 腾讯开源微服务架构 Tars,高性能 RPC 开发框架

    腾讯微服务架构 Tars 于今日正式开源. Tars 取名于电影“星际穿越”中的机器人,是支持多语言的高性能 RPC 开发框架和配套一体化的服务治理平台,可以帮助企业或者用户以微服务的方式快速构建稳定 ...

  3. 20190817 On Java8 第七章 封装

    第七章 封装 访问控制权限的等级,从"最大权限"到"最小权限"依次是:public,protected,包访问权限(没有关键字)和 private. 包的概念 ...

  4. #python# 使用代理和不使用代理对比

    import urllib.request url='http://httpbin.org/ip' #不使用代理 response1=urllib.request.urlopen(url) #设置代理 ...

  5. IEnumerable和IEnumerator 详解 分类: C# 2014-12-05 11:47 18人阅读 评论(0) 收藏

    原:<div class="article_title"> <span class="ico ico_type_Original">&l ...

  6. 攻防世界--python-trade

    测试文件:https://adworld.xctf.org.cn/media/task/attachments/69c8f29912ae4f679d92a6cd36c33196.pyc 这里需要用到一 ...

  7. saltstack的高级管理

    一.saltstack的状态管理 状态管理官网: https://www.unixhot.com/docs/saltstack/ref/states/all/index.html 1)状态分析 [ro ...

  8. Runtime-iOS运行时应用篇

    一.动态方法交换:Method Swizzling实现动态方法交换(Method Swizzling )是Runtime中最具盛名的应用场景,其原理是:通过Runtime获取到方法实现的地址,进而动态 ...

  9. 2018-8-10-win10-uwp-线程池

    title author date CreateTime categories win10 uwp 线程池 lindexi 2018-08-10 19:16:50 +0800 2018-05-15 1 ...

  10. python常用函数 D

    defaultdict(set_type) 可以定义字典多值映射,入参类型决定value类型. 例子: deque:(int) 保留最后N个元素 例子: Decimal(float) 直接对浮点数进行 ...