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

  1. 3 3 2
  2. 1 2 1 0
  3. 2 3 1 0
  4. 1 3 1 1
  5. 3 3 2
  6. 1 2 1 0
  7. 2 3 1 0
  8. 1 3 0 5

Sample Output

  1. 1.75000000
  2. 2.00000000
  3.  
  4. 这东西实在太好用了,可惜省赛不会...simpson公式就是求定积分用的,这题的F函数就是在时间点为 t 时从 1点到n点的最小花费.
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. const double INF = ;
  5. struct Edge{
  6. int v,next;
  7. int c,d;
  8. }edge[];
  9. int head[],tot;
  10. int n,m,T;
  11. void init(){
  12. memset(head,-,sizeof(head));
  13. tot = ;
  14. }
  15. void addEdge(int u,int v,int c,int d,int &k){
  16. edge[k].v = v,edge[k].c = c,edge[k].d = d,edge[k].next = head[u],head[u] = k++;
  17. }
  18. double dis[];
  19. bool vis[];
  20. double F(double x){
  21. for(int i=;i<=n;i++){
  22. dis[i] = INF;
  23. vis[i] = false;
  24. }
  25. dis[] = ;
  26. queue<int> q;
  27. q.push();
  28. while(!q.empty()){
  29. int u = q.front();
  30. q.pop();
  31. vis[u] = false;
  32. for(int k = head[u];k!=-;k = edge[k].next){
  33. int v = edge[k].v,c = edge[k].c,d = edge[k].d;
  34. double t = x*c+d;
  35. if(dis[v]>dis[u]+t){
  36. dis[v] = dis[u]+t;
  37. if(!vis[v]){
  38. vis[v] = true;
  39. q.push(v);
  40. }
  41. }
  42. }
  43. }
  44. double ret = dis[n];
  45. return ret;
  46. }
  47. // 三点simpson法。这里要求F是一个全局函数
  48. double simpson(double a,double b){
  49. double c = a+(b-a)/;
  50. return (F(a) + *F(c) + F(b))*(b-a)/;
  51. }
  52. // 自适应Simpson公式(递归过程)。已知整个区间[a,b]上的三点simpson值A
  53. double asr(double a , double b ,double eps ,double A){
  54. double c = a+ (b-a)/;
  55. double L = simpson(a,c) ,R = simpson(c,b);
  56. if(fabs(A-L-R)<=*eps) return L + R +(A-L-R)/;
  57. return asr(a,c,eps/,L) + asr(c,b,eps/,R);
  58. }
  59. // 自适应Simpson公式(主过程)
  60. double asr(double a, double b, double eps) {
  61. return asr(a, b, eps, simpson(a, b));
  62. }
  63.  
  64. int main()
  65. {
  66. while(scanf("%d%d%d",&n,&m,&T)!=EOF){
  67. init();
  68. for(int i=;i<m;i++){
  69. int u,v,c,d;
  70. scanf("%d%d%d%d",&u,&v,&c,&d);
  71. addEdge(u,v,c,d,tot);
  72. }
  73. double ans = asr(,T,1e-)/T;
  74. printf("%.8lf\n",ans);
  75. }
  76. return ;
  77. }

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+DAom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s3eWzIruvgaPJYArj3g3AonDDH57MPDyABwCPIvJeWAEsG0KrPeCyA1UGWBgTZAPgiBeD68i+RAD4F8DoFXEPPPohP4sFXsO5/EJexQJI/xW3G5C4a0Nei2SQABc35Y0PlbSSgbc7e/XpDZRMLdJu9LyF515GAaJW1pSADqNdAJZmC9aJdsPmXDtMoOZMwuO1iYB3kNeX5MK9GAPcfnsEZfCzgL0aewb8FuORq0kD+dSK4nDyargekqJ2/khwGd6mAu+Bq6VXIhtDG+birFgdCbghzQVct9gdTAOo5CE4zrN3C84RT0e+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. 1 2
  3. 2 8

Sample Output

  1. 0
  2. 6593
  3. -312
  4.  
  5. 这题更好用..直接带进去算
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4.  
  5. double F(double x){
  6. return sin(x)/x;
  7. }
  8. // 三点simpson法。这里要求F是一个全局函数
  9. double simpson(double a,double b){
  10. double c = a+(b-a)/;
  11. return (F(a) + *F(c) + F(b))*(b-a)/;
  12. }
  13. // 自适应Simpson公式(递归过程)。已知整个区间[a,b]上的三点simpson值A
  14. double asr(double a , double b ,double eps ,double A){
  15. double c = a+ (b-a)/;
  16. double L = simpson(a,c) ,R = simpson(c,b);
  17. if(fabs(A-L-R)<=*eps) return L + R +(A-L-R)/;
  18. return asr(a,c,eps/,L) + asr(c,b,eps/,R);
  19. }
  20. // 自适应Simpson公式(主过程)
  21. double asr(double a, double b, double eps) {
  22. return asr(a, b, eps, simpson(a, b));
  23. }
  24.  
  25. int main()
  26. {
  27. double a,b;
  28. while(scanf("%lf%lf",&a,&b)!=EOF){
  29. printf("%d\n",(int)(asr(a,b,1e-)*));
  30. }
  31. return ;
  32. }
  1.  

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. Hbase(五) hbase内部原理

    一.系统架构 客户端连接hbase依赖于zookeeper,hbase存储依赖于hadoop client: 1.包含访问 hbase 的接口, client 维护着一些 cache(缓存) 来加快对 ...

  2. 《剑指offer》— JavaScript(11)二进制中1的个数

    二进制中1的个数 题目描述 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示. 思路一 用1和n进行位运算,结果为1则n的二进制最右边一位为1,否则为0: 将n二进制形式右移1位,继续与 ...

  3. 使用gulp进行css、js压缩

    var gulp = require('gulp'); var cleanCSS = require('gulp-clean-css'); var concatCss = require('gulp- ...

  4. 题解【bzoj3240 [NOI2013]矩阵游戏】

    挖坑2333 等我把代码写完了再写

  5. 「Django」rest_framework学习系列-权限认证

    权限认证:1.项目下utils文件写permissions.py文件 from rest_framework.permissions import BasePermission class SVIPP ...

  6. [DeeplearningAI笔记]序列模型2.10词嵌入除偏

    5.2自然语言处理 觉得有用的话,欢迎一起讨论相互学习~Follow Me 2.10词嵌入除偏 Debiasing word embeddings Bolukbasi T, Chang K W, Zo ...

  7. turn服务部署

    centos7.2 git clone https://github.com/coturn/coturnyum -y install openssl-develyum install openssl ...

  8. IIS7.5 HTTP 错误500.19-Internal Server Error 无法访问请求的页面,因为该页的相关配置数据无效

    IIS7.5 HTTP 错误500.19-Internal Server Error 无法访问请求的页面,因为该页的相关配置数据无效 --------------------------------- ...

  9. 4.redis设计与实现--跳跃表

    1.跳跃表由两个结构体构成: 2.总结:

  10. HDU 6199 DP 滚动数组

    强行卡内存 这题在CF上好像有道极相似的题 可以想到状态设计为dp[f][i][k]表示f在取完i-1时,此时可以取k个或k+1个的状态下的最大值.之前以为n是1e5,自己想不到怎么设计状态真的辣鸡, ...