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. SCWS中文分词,功能函数实例应用

    结合前文的demo演示,现写一个实用的功能函数,使用方法:header('Content-Type:text/html;charset=UTF-8');$text        = '我是一个中国人, ...

  2. 解题:APIO 2008 免费道路

    题面 我们发现我们可以很容易知道最终完成的生成树中有多少鹅卵石路,但是我们不好得到这棵生成树的结构,所以我们尽量“谨慎”地完成生成树·,最好是一点点加到我们要达到的标准而不是通过删掉一些东西来完成 我 ...

  3. Shell颜色及显示git分支配置

    # Ubuntu终端下命令行颜色配置 ## Parses out the branch name from .git/HEAD: find_git_branch () { local dir=. he ...

  4. Java之基础20160806

    注意这里介绍的JAVA基础是指你对C语言已经比较熟练或者有一定基础了,再学习如下这知识就会比较快. 1.JAVA也是从MAIN开始执行,但是要先定义类,文件名要与类名一致并且类名首字母要大写,同时JA ...

  5. Hdu3022 Sum of Digits

    Sum of Digits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  6. command not found: django-admin.py

    http://www.cnblogs.com/Xjng/p/3559984.html django-admin.py startproject projectname  其中projectname 为 ...

  7. TCP与UDP区别详解

    TCP协议与UDP协议的区别    首先咱们弄清楚,TCP协议和UCP协议与TCP/IP协议的联系,很多人犯糊涂了,一直都是说TCP/IP协议与UDP协议的区别,我觉得这是没有从本质上弄清楚网络通信! ...

  8. libcurl在mingw下编译

    通过命令提示符进入 curl-7.27.0 文件夹输入 mingw32-make mingw32 进行生成(这里我只需要普通的功能,于是没有加附加的选项)编译完成后,在 lib 文件夹中会有我们需要的 ...

  9. 关于WEB-INF目录不提供外部访问及JSP引用 js,css 文件路径问题

    在 web 项目开发过程中,我们常常使用到 JSP,以及对静态资源,js,css 等引用,但是我们应该把这些资源文件放在哪个目录下面咧,怎么引用. 当然如果是前后端分离的项目倒不用考虑这些. WEB- ...

  10. 【BZOJ】1706: [usaco2007 Nov]relays 奶牛接力跑

    [题意]给定m条边的无向图,起点s,终点t,要求找出s到t恰好经过n条边的最短路径.n<=10^6,m<=100. [算法]floyd+矩阵快速幂 [题解] 先对点离散化,得到点数N. 对 ...