[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=17,QN=17,M=207;
const double EPS=1e-15,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+10];double dis[N];bool use[N];
double F(double x){
    for(int i=2;i<=n;++i)dis[i]=INF;
    int h=0,t=1;dis[q[t]=1]=0;
    for(int v;h!=t;){
        if((++h)==QN)h=0;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=0;use[q[t]=u]=true;
            }
        }
    }
    return dis[n];
}
double Simpson(double l,double r){
    return (r-l)*(F(l)+4*F((l+r)/2)+F(r))/6;
}
double Abs(double x){return x<0?-x:x;}
double Integral(double l,double r,double S){
    double mid=(l+r)/2;
    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=0;memset(fi,0,sizeof fi);
        for(int i=1,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(0,T,Simpson(0,T))/T;
        printf("%.8f\n",ans);
    }
    return 0;
} 
时间: 2024-10-25 20:00:52

[CSU1806]Toll的相关文章

1774: [Usaco2009 Dec]Toll 过路费

1774: [Usaco2009 Dec]Toll 过路费 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 263  Solved: 154[Submit][Status][Discuss] Description 跟所有人一样,农夫约翰以着宁教我负天下牛,休叫天下牛负我的伟大精神,日日夜夜苦思生 财之道.为了发财,他设置了一系列的规章制度,使得任何一只奶牛在农场中的道路行走,都 要向农夫约翰上交过路费. 农场中由N(1 <= N <= 250)片

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

P2966 [USACO09DEC]牛收费路径Cow Toll Paths 题目描述 Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has set up a series of tolls that the cows will pay when they traverse the cowpaths throughout the farm. The cows mo

洛谷 P2966 [USACO09DEC]牛收费路径Cow Toll Paths

题目描述 Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has set up a series of tolls that the cows will pay when they traverse the cowpaths throughout the farm. The cows move from any of the N (1 <= N <= 250)

UVA 10537 - The Toll! Revisited(dijstra扩展)

UVA 10537 - The Toll! Revisited 题目链接 题意:给定一个无向图,大写字母是城市,小写字母是村庄,经过城市交过路费为当前货物的%5,路过村庄固定交1,给定起点终点和到目标地点要剩下的货物,问最少要带多少货物上路,并输出路径,如果有多种方案,要求字典序最小 思路:dijstra的逆向运用,d数组含义变成到该结点至少需要这么多货物,然后反向建图,从终点向起点反向做一遍 这题被坑了..并不是输出的城市才存在,比如下面这组样例 0 1 A A 应该输出 1 A 代码: #i

洛谷 2966 [USACO09DEC]牛收费路径Cow Toll Paths

https://www.luogu.org/problem/show?pid=2966 题目描述 Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has set up a series of tolls that the cows will pay when they traverse the cowpaths throughout the farm. The c

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

Toll! Revisited 大致题意:有两种节点,一种是大写字母,一种是小写字母.首先输入m条边,当经过小写字母时需要付一单位的过路费,当经过大写字母时,要付当前财务的1/20做过路费.问在起点最少需要带多少物品使到达终点时还有k个物品.当有多条符合条件的路径时输出字典序最小的一个. 思路:已知终点的权值,那么可以从终点向前推.求终点到起点的最短路径,然后按字典序打印路径. 比较难处理的是:向前推时前驱节点的权值计算.列个方程算算就可以了,主要时不能整除的情况. 计算前驱结点dis值的时候,

【BZOJ 1774】 [Usaco2009 Dec]Toll 过路费

1774: [Usaco2009 Dec]Toll 过路费 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 266 Solved: 157 [Submit][Status][Discuss] Description 跟所有人一样,农夫约翰以着宁教我负天下牛,休叫天下牛负我的伟大精神,日日夜夜苦思生 财之道.为了发财,他设置了一系列的规章制度,使得任何一只奶牛在农场中的道路行走,都 要向农夫约翰上交过路费. 农场中由N(1 <= N <= 250)片

UVA10537 Toll! Revisited

difkstra + 路径输出 The Toll! Revisited Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu [Submit]   [Go Back]   [Status] Description Problem G Toll! Revisited Input: Standard Input Output: Standard Output Time Limit: 1 Second Sindbad

UVA - 10537 The Toll! Revisited (最短路变形逆推)

Description Problem G Toll! Revisited Input: Standard Input Output: Standard Output Time Limit: 1 Second Sindbad the Sailor sold 66 silver spoons to the Sultan of Samarkand. The selling was quite easy; but delivering was complicated. The items were t