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. 洛谷 P2233 [HNOI2002]公交车路线 解题报告

    P2233 [HNOI2002]公交车路线 题目背景 在长沙城新建的环城公路上一共有8个公交站,分别为A.B.C.D.E.F.G.H.公共汽车只能够在相邻的两个公交站之间运行,因此你从某一个公交站到另 ...

  2. linux内核分析 第二周 操作系统是如何工作的

    银雪纯 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.计算机是如何工作的 ...

  3. Linux之静态库与动态库20160706

    所谓静态链接是指把要调用的函数或者过程链接到可执行文件中,成为可执行文件的一部分.当多个程序都调用相同函数时,内存中就会存在这个函数的多个拷贝,这样就浪费了宝贵的内存资源..so文件是共享库文件(动态 ...

  4. hihocoder #1584 : Bounce

    题意; 有一个n*m的网格阵,球从左上角开始在网格中碰撞,碰到边界就直角反弹,到达格子的角落结束,求途中经过一次的格子数. 代码: //神马规律啊,设x表示球与垂直面的撞击次数,y为球与水平墙面的撞击 ...

  5. 「Django」rest_framework学习系列-视图

    方式一 1.settings设置 INSTALLED_APPS = [ ... 'rest_framework', ] 2.views设置 from rest_framework.response i ...

  6. jeecms上传文件限制导致413-Request Entity Too Large

    1:spring mvc 上传限制大小  配置是否允许在上传文件的大小 <bean id="multipartResolver" class="org.spring ...

  7. codevs 2488 绿豆蛙的归宿

    2488 绿豆蛙的归宿 http://codevs.cn/problem/2488/  时间限制: 1 s  空间限制: 64000 KB  题目等级 : 黄金 Gold   题目描述 Descrip ...

  8. ZOJ 3964 NIM变形

    LINK 题意:n堆石子,Alice 和 Bob 轮流取石子,谁不能再取或被对方取完为败.但是对于alice拥有限制:b=0此堆正常无限制:b=1此堆Alice只能取奇数个石子:b=2只能取偶数个石子 ...

  9. 应用于网站导航中的 12 个 jQuery 插件

    当考虑到网页设计时,导航被认为是使网页以用户友好方式展现的一个重要部分.在现代的交互网站中,导航起着至关重要的作用,如果没有正确地处理会影响你网站的访问.适当的导航工具能够帮助用户在网站的不同页面内容 ...

  10. Lua只读表

    利用Lua的元表(metatable)和元函数(metafunction)可以很简单的实现此功能. 其实现大致分为三个部分 1.禁止在表中创建新值 2.禁止改变已有的值 3.将子表也变为只读 1.禁止 ...