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


    分析:根据这个题学了一发自适应simpson积分(原来积分还可以这么求),然后就是套模板了

            学习自适应simpson积分:http://blog.csdn.net/greatwall1995/article/details/8639135

    #include <cstdio>
    #include <cstring>
    #include <queue>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    typedef long long LL;
    const int N = 1e2 + 5;
    const double eps = 1e-9;
    const double INF = 1e12;
    int n,m,T,tot,head[15];
    int a[N],b[N],c[N],d[N];
    bool vis[15];
    double dis[N];
    struct Edge{
      int v,next;
      double w;
      Edge(int v=0,double w=0){
        this->v=v;this->w=w;
      }
      bool operator<(const Edge &rhs)const{
        return w>rhs.w;
      }
    }edge[N];
    void add(int u,int v,double w){
      edge[tot].v=v;
      edge[tot].w=w;
      edge[tot].next=head[u];
      head[u]=tot++;
    }
    priority_queue<Edge>q;
    double F(double t){
       memset(head,-1,sizeof(head));tot=0;
       memset(vis,false,sizeof(vis));
       for(int i=1;i<=n;++i)dis[i]=INF;
       dis[1]=0;
       for(int i=0;i<m;++i){
        add(a[i],b[i],c[i]*t+d[i]);
       }
       q.push(Edge(1,dis[1]));
       while(!q.empty()){
          int u=q.top().v;
          q.pop();if(vis[u])continue;
          vis[u]=true;
          for(int i=head[u];~i;i=edge[i].next){
              int v=edge[i].v;
              if(!vis[v]&&dis[v]>dis[u]+edge[i].w){
                 dis[v]=dis[u]+edge[i].w;
                 q.push(Edge(v,dis[v]));
              }
          }
       }
       return dis[n];
    }
    double simpson(double a,double b){
      double c=a+(b-a)/2;
      return (F(a)+4*F(c)+F(b))*(b-a)/6;
    }
    double asr(double a,double b,double eps,double A){
        double c=a+(b-a)/2;
        double L = simpson(a,c),R=simpson(c,b);
        if(fabs(L+R-A)<=15*eps)return L+R+(L+R-A)/15.0;
        return asr(a,c,eps/2,L)+asr(c,b,eps/2,R);
    }
    double get(double a,double b,double eps){
      return asr(a,b,eps,simpson(a,b));
    }
    int main(){
      while(~scanf("%d%d%d",&n,&m,&T)){
        for(int i=0;i<m;++i)scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
        printf("%.6f
    ",get(0,T,eps)/T);
      }
      return 0;
    }
    View Code
  • 相关阅读:
    elastic-job 新手指南
    最基本的区块链hello world(python3实现)
    python:函数的高级特性
    python高级特性:切片/迭代/列表生成式/生成器
    python:函数中五花八门的参数形式(茴香豆的『回』字有四种写法)
    python:爬虫入门
    python: 序列化/反序列化及对象的深拷贝/浅拷贝
    python中的zip、lambda、map操作
    python面向对象笔记
    RxJava2学习笔记(3)
  • 原文地址:https://www.cnblogs.com/shuguangzw/p/5842288.html
Copyright © 2020-2023  润新知