题目: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. Entity Framework 中遇到的一些小问题

    一.在多表关联中,一个表中有另一个表的model累,在Include方法里提示lambda表达式不是委托类型,这时候需要using System.Data.Entity; 二.插入数据时,主键并非自增 ...

  2. JAVA中JavaBean对象之间属性拷贝的方法

    JAVA中JavaBean对象之间的拷贝通常是用get/set方法,但如果你有两个属性相同的JavaBean或有大部分属性相同的JavaBean,对于这种情况,可以采用以下几个简便方法处理. 下面对这 ...

  3. 16、NumPy ——字节交换

    NumPy 字节交换 在几乎所有的机器上,多字节对象都被存储为连续的字节序列.字节顺序,是跨越多字节的程序对象的存储规则. 大端模式:指数据的高字节保存在内存的低地址中,而数据的低字节保存在内存的高地 ...

  4. CodeChef Little Elephant and Balance

    Given an array A1,A2...AN, you have to print the size of the largest contiguous subarray such that L ...

  5. 图标,空格,大小尖括号,段落,换行,标题,div白板,span白板

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. Windows程序设计--(三)窗口与消息

    3.1 窗口的创建 3.1.1 系统结构概述 所谓「Windows给程序发送消息」,是指Windows呼叫程序中的一个函数,该函数的参数描述了这个特定消息.这种位于Windows程序中的函数称为「窗口 ...

  7. 安装weblogic界面安装

    如果中间有任何问题请联系作者:291562721 界面安装weblogic首先 需要工具: 链接:https://pan.baidu.com/s/1x3uYxsnycjT2Xi2TOTbDdQ 提取码 ...

  8. JS 逻辑非!简单总结

    !""                  true!"aaa"          false""==false          true ...

  9. console.log的高级用法

    //基本用法 console.log('最常见用法\n换行'); console.error('输出错误信息 会以红色显示'); console.warn('打印警告信息 会以黄色显示'); cons ...

  10. UI库colorui的使用————小程序

    UI库colorui的使用----小程序 把colorui文件放到你的小程序中 包含文件: icon.wxss+main.wxss+components(文件夹里有icon和一些组件)+animati ...