zoukankan      html  css  js  c++  java
  • luogu_P1016 旅行家的预算

    贪心,很有难度!!!

    #include<iostream>
    #include<cstdio>
    
    #define ri register int
    #define u int
    
    namespace opt {
        
        inline u in() {
            u x(0),f(1);
            char s=getchar();
            while(s<'0'||s>'9') {
                if(s=='-')f=-1;
                s=getchar();
            }
            while(s>='0'&&s<='9') {
                x=(x<<1)+(x<<3)+s-'0';
                s=getchar();
            }
            return x*f;
        }
        
        u pow[10]= {1};
        
        inline double dbin() {
            u x(0),y(0),cnt(0),f(1);
            char s=getchar();
            while(s<'0'||s>'9') {
                if(s=='-') f=-1;
                s=getchar();
            }
            while(s>='0'&&s<='9') {
                x=(x<<1)+(x<<3)+s-'0';
                s=getchar();
            }
            s=getchar();
            while(s>='0'&&s<='9') {
                ++cnt,y=(y<<1)+(y<<3)+s-'0';
                s=getchar();
            }
            return f*(x+((double)y)/pow[cnt]);
        }
    
    }
    
    using opt::dbin;
    using opt::in;
    
    #include<algorithm>
    #include<cstring>
    
    #define NN 505
    
    namespace mainstay {
        
        double D1,C,D2,P,re,rest,d[NN],p[NN]; 
        
        u N;
    
        inline void solve() {
            for(ri i(1); i<=8; ++i) opt::pow[i]=opt::pow[i-1]*10;
            D1=dbin(),C=dbin(),D2=dbin(),p[0]=dbin(),N=in(),d[N+1]=D1;
            //距离D1,容量C,D2 km/l 
            for(ri i(1);i<=N;++i) d[i]=dbin(),p[i]=dbin();//d据起点距离,p价钱 
            for(ri i(0);i<=N;++i){
                if(C*D2<d[i+1]-d[i]) {//中途夭折,加满油都到不了下一个油站。。。 
                    printf("No Solution");
                    return;
                }
                double to(d[i]+C*D2);
                u poi(i);//在当前点加满油到达的最右 ,poi:最划算的点
                for(ri j(i+1);j<=N+1;++j){
                    if(d[j]<=to&&p[j]<p[i]){//在最右内且油价更便宜 
                        poi=j;
                        break;
                    }
                }
                if(poi^i) {
                    if(rest<(d[poi]-d[i])/D2) re+=((d[poi]-d[i])/D2-rest)*p[i],rest=(d[poi]-d[i])/D2;
                }
                else re+=(C-rest)*p[i],rest=C;
                rest-=(d[i+1]-d[i])/D2;
            }
            printf("%.2f",re);
        }
    
    }
    
    int main() {
    
        //freopen("x.txt","r",stdin);
        mainstay::solve();
    
    }
  • 相关阅读:
    oldboy_python_bankSystem practice
    【HCIE-RS复习】- PPP
    【HCIE-RS】PPP详解
    【HCIE-RS】考试说明
    【HCIE-RS】杭州考场(个人考试心得体会)
    DataWorks功能实践速览 05——循环与遍历
    Serverless 工程实践 | 零基础上手 Knative 应用
    前后端、多语言、跨云部署,全链路追踪到底有多难?
    多任务多目标CTR预估技术
    开放搜索查询分析服务架构解读
  • 原文地址:https://www.cnblogs.com/ling-zhi/p/11863733.html
Copyright © 2011-2022 走看看