1806: Toll

Time Limit: 5 Sec  Memory Limit: 128 MB  Special Judge
Submit: 256  Solved: 74
[Submit][Status][Web Board]

Description

 In ICPCCamp, there are n cities and m unidirectional roads between cities. The i-th road goes from the ai-th city to the bi-th city. For each pair of cities u and v, there is at most one road from u to v.
As traffic in ICPCCamp is becoming heavier, toll of the roads also varies. At time t, one should pay (ci⋅t+di) dollars to travel along the i-th road.
Bobo living in the 1-st city would like to go to the n-th city. He
wants to know the average money he must spend at least if he starts from
city 1 at t∈[0,T]. Note that since Bobo's car is super-fast, traveling on the roads costs him no time.
Formally, if f(t) is the minimum money he should pay from city 1 to city n at time t, Bobo would like to find

Input

The first line contains 3 integers n,m,T (2≤n≤10,1≤m≤n(n-1),1≤T≤104).
The i-th of the following m lines contains 4 integers ai,bi,ci,di (1≤ai,bi≤n,ai≠bi,0≤ci,di≤103).
It is guaranteed that Bobo is able to drive from city 1 to city n.

Output

 A floating number denotes the answer. It will be considered correct if its absolute or relative error does not exceed 10-6.

Sample Input

3 3 2
1 2 1 0
2 3 1 0
1 3 1 1
3 3 2
1 2 1 0
2 3 1 0
1 3 0 5

Sample Output

1.75000000
2.00000000 这东西实在太好用了,可惜省赛不会...simpson公式就是求定积分用的,这题的F函数就是在时间点为 t 时从 1点到n点的最小花费.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const double INF = ;
struct Edge{
int v,next;
int c,d;
}edge[];
int head[],tot;
int n,m,T;
void init(){
memset(head,-,sizeof(head));
tot = ;
}
void addEdge(int u,int v,int c,int d,int &k){
edge[k].v = v,edge[k].c = c,edge[k].d = d,edge[k].next = head[u],head[u] = k++;
}
double dis[];
bool vis[];
double F(double x){
for(int i=;i<=n;i++){
dis[i] = INF;
vis[i] = false;
}
dis[] = ;
queue<int> q;
q.push();
while(!q.empty()){
int u = q.front();
q.pop();
vis[u] = false;
for(int k = head[u];k!=-;k = edge[k].next){
int v = edge[k].v,c = edge[k].c,d = edge[k].d;
double t = x*c+d;
if(dis[v]>dis[u]+t){
dis[v] = dis[u]+t;
if(!vis[v]){
vis[v] = true;
q.push(v);
}
}
}
}
double ret = dis[n];
return ret;
}
// 三点simpson法。这里要求F是一个全局函数
double simpson(double a,double b){
double c = a+(b-a)/;
return (F(a) + *F(c) + F(b))*(b-a)/;
}
// 自适应Simpson公式(递归过程)。已知整个区间[a,b]上的三点simpson值A
double asr(double a , double b ,double eps ,double A){
double c = a+ (b-a)/;
double L = simpson(a,c) ,R = simpson(c,b);
if(fabs(A-L-R)<=*eps) return L + R +(A-L-R)/;
return asr(a,c,eps/,L) + asr(c,b,eps/,R);
}
// 自适应Simpson公式(主过程)
double asr(double a, double b, double eps) {
return asr(a, b, eps, simpson(a, b));
} int main()
{
while(scanf("%d%d%d",&n,&m,&T)!=EOF){
init();
for(int i=;i<m;i++){
int u,v,c,d;
scanf("%d%d%d%d",&u,&v,&c,&d);
addEdge(u,v,c,d,tot);
}
double ans = asr(,T,1e-)/T;
printf("%.8lf\n",ans);
}
return ;
}

csu 1742

1742: Integral Function

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 79  Solved: 27
[Submit][Status][Web Board]

Description

In mathematics, several function are unable to integral. For example:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAX8AAADYAQMAAAA55HHGAAAABlBMVEX///8AAABVwtN+AAAFC0lEQVR4nO3ZMY/kNBQAYFs+XZq9CeWedEz+wnTsitXkr2xHySKaQawmOa0EDTr+Ab+DAomgK7Y56Voq5BMFraVrXFgx7zlxknHsxIZDRzFPKyXK5Jt1PM6z80LIOc5xjnP8z4MKu/ek29QrgEm796Lb8BWQKbt36DZ30aBv200soE233caCrO62eSywJ2bNMhh6yTaF8WUw/A57e2AFDDH0jlg4aRoHuyOXzprEcN593PnjmNqvfB4JCu4cGHuz9P+HMCjiQDaC2gdY4xzIhwN5MnA/GgFVcFteEVaX9SowgznTPxAqodGakwJPu8Ixm/MgyLUimSTVSy3MpcJQh80CKJgipWT6ey0JtIqULSkbkokg2BNFvpRP9Y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RT0e+qxf7I9Au4QPf1kKkWh4AC4L6VMNXiEJBegJXCINhOn2VNmGpxCAgA7qsYUy32B9McwC8ueLMAGrKl7ls3U/z1By4ICnaoowFeb/HqG/c/iDDAj+W3zhH/K4HJ97ndOr7V8QZrDs6RFTCPZDBWi/4rsNJLHwA8i32T+I/B81RwPStFr8QuFZhqcUqYanFCdNXihOiqxfHRV4vjo68WJ4B2WiKOAV21OAHI8Hzijb5aHB+sGcp75zjHOT5m/A188CFzlzTsVAAAAABJRU5ErkJggg==" alt="" name="图片 1" width="113" height="64" align="bottom" border="0" data-pagespeed-url-hash="2268721189" />

But you can get the answer by computer.

Input

There are no more than T (T<=30) cases. Each case include two integer a, b (0<a <= b<=10).

Output

Each case output an answer.

(Please output the answer by ‘‘ printf (“%d\n”,(int)(answer*10000)) ‘‘ ).

Sample Input

1 1
1 2
2 8

Sample Output

0
6593
-312 这题更好用..直接带进去算
#include <bits/stdc++.h>
using namespace std;
typedef long long LL; double F(double x){
return sin(x)/x;
}
// 三点simpson法。这里要求F是一个全局函数
double simpson(double a,double b){
double c = a+(b-a)/;
return (F(a) + *F(c) + F(b))*(b-a)/;
}
// 自适应Simpson公式(递归过程)。已知整个区间[a,b]上的三点simpson值A
double asr(double a , double b ,double eps ,double A){
double c = a+ (b-a)/;
double L = simpson(a,c) ,R = simpson(c,b);
if(fabs(A-L-R)<=*eps) return L + R +(A-L-R)/;
return asr(a,c,eps/,L) + asr(c,b,eps/,R);
}
// 自适应Simpson公式(主过程)
double asr(double a, double b, double eps) {
return asr(a, b, eps, simpson(a, b));
} int main()
{
double a,b;
while(scanf("%lf%lf",&a,&b)!=EOF){
printf("%d\n",(int)(asr(a,b,1e-)*));
}
return ;
}
 

csu 1806 & csu 1742 (simpson公式+最短路)的更多相关文章

  1. CSU 1806 Toll 自适应simpson积分+最短路

    分析:根据这个题学了一发自适应simpson积分(原来积分还可以这么求),然后就是套模板了 学习自适应simpson积分:http://blog.csdn.net/greatwall1995/arti ...

  2. 【最短路】【数学】CSU 1806 Toll (2016湖南省第十二届大学生计算机程序设计竞赛)

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1806 题目大意: N个点M条有向边,给一个时间T(2≤n≤10,1≤m≤n(n-1), ...

  3. simpson公式求定积分(模板)

    #include<cstdio> #include<cmath> #include <algorithm> using namespace std; double ...

  4. CSU 1333 Funny Car Racing (最短路)

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1333 解题报告:一个图里面有n个点和m条单向边,注意是单向边,然后每条路开a秒关闭b秒 ...

  5. CSU 1806 Toll

    最短路,自适应$Simpson$积分. 看了别人的题解才知道有个东西叫自适应$Simpson$积分. 有这样一个积分公式:$\int_a^b {f(x)dx}  \approx \frac{{b - ...

  6. CSU 2005 Nearest Maintenance Point(最短路+bitset)

    https://vjudge.net/problem/CSU-2005 题意:给出带权值的图,图上有一些特殊点,现在给出q个询问,对于每个询问,输出离该点最近的特殊点,如果有多个,则按升序输出. 思路 ...

  7. 数值积分之Simpson公式与梯形公式

    Simpson(辛普森)公式和梯形公式是求数值积分中很重要的两个公式,可以帮助我们使用计算机求解数值积分,而在使用过程中也有多种方式,比如复合公式和变步长公式.这里分别给出其简单实现(C++版): 1 ...

  8. Simpson公式的应用(HDU 1724/ HDU 1071)

    辛普森积分法 - 维基百科,自由的百科全书 Simpson's rule - Wikipedia, the free encyclopedia 利用这个公式,用二分的方法来计算积分. 1071 ( T ...

  9. 自适应Simpson公式

    参考刘汝佳<算法指南>P163 #include<cstdio> #include<cmath> double a; double F(double x){ +*a ...

随机推荐

  1. powershell网络钓鱼获取用户密码

    1.powershell网络钓鱼脚本: https://raw.githubusercontent.com/enigma0x3/Invoke-LoginPrompt/master/Invoke-Log ...

  2. HDU.1846 Brave Game (博弈论 巴什博弈)

    HDU.1846 Brave Game (博弈论 巴什博弈) 题意分析 巴什博奕裸题 博弈论快速入门 代码总览 include <bits/stdc++.h> using namespac ...

  3. 题解 P3153 【[CQOI2009]跳舞】

    P3153 [CQOI2009]跳舞 题目描述 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲.有一些男孩女孩相互喜欢 ...

  4. SDK代码记录

    zynq中SDK相关API的学习.记录常用函数 /*************************************************************************** ...

  5. RabbitMQ的原理和使用

    转载:RabbitMQ从入门到精通 转载:轻松搞定RabbitMQ 转载:RabbitMQ Java入门教程 一.RabbitMQ AMQP,即Advanced Message Queuing Pro ...

  6. HDU 3977 斐波那契循环节

    这类型的题目其实没什么意思..知道怎么做后,就有固定套路了..而且感觉这东西要出的很难的话,有这种方法解常数会比较大吧..所以一般最多套一些比较简单的直接可以暴力求循环节的题目了.. /** @Dat ...

  7. Spark Core 资源调度与任务调度(standalone client 流程描述)

    Spark Core 资源调度与任务调度(standalone client 流程描述) Spark集群启动:      集群启动后,Worker会向Master汇报资源情况(实际上将Worker的资 ...

  8. 【洛谷 P3338】 [ZJOI2014]力(FFT)

    题目链接 \[\Huge{E_i=\sum_{j=1}^{i-1}\frac{q_j}{(i-j)^2}-\sum_{j=i+1}^{n}\frac{q_j}{(i-j)^2}}\] 设\(A[i]= ...

  9. Django之Form组件验证

    今天来谈谈Django的Form组件操作 Django中的Form一般有两种功能: ·输入html ·验证用户输入 Form验证流程 ·定义规则(是一个类)    ·前端把数据提交过来 ·匹配规则 · ...

  10. 数据类型的判断 --Object.prototype.toString.call(obj)精准检测对象类型

    数据类型的判断 typeof typeof返回一个表示数据类型的字符串,返回结果包括:number.boolean.string.symbol.object.undefined.function等7种 ...