• LuoguP1016 旅行家的预算 (贪心)


    胡一个错误代码都能有75pts
    忘了怎么手写deque其实是懒

    #include <cstdio>
    #include <iostream>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #define R(a,b,c) for(register int a = (b); (a) <= (c); ++(a))
    #define nR(a,b,c) for(register int a = (b); (a) >= (c); --(a))
    #define Fill(a,b) memset(a, b, sizeof(a))
    #define Max(a,b) ((a) > (b) ? (a) : (b))
    #define Min(a,b) ((a) < (b) ? (a) : (b))
    #define Swap(a,b) ((a) ^= (b) ^= (a) ^= (b))
    
    //#define ON_DEBUGG
    
    #ifdef ON_DEBUGG
    
    #define D_e_Line printf("
    ----------
    ") 
    #define D_e(x) cout << (#x) << " : " << x << endl
    #define Pause() system("pause")
    #define FileOpen() freopen("in.txt", "r", stdin)
    
    #else
    
    #define D_e_Line ;
    #define D_e(x) ;
    #define Pause() ;
    #define FileOpen() ;
    
    #endif
    using namespace std;
    struct ios{
    	template<typename ATP>inline ios& operator >> (ATP &x){
    		x = 0; int f = 1; char ch;
    		for(ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
    		while(ch >= '0' && ch <= '9') x = x * 10 + (ch ^ '0'), ch = getchar();
    		x *= f;
    		return *this;
    	}
    }io;
    
    template<typename ATP>inline ATP max(ATP &a, ATP &b){
    	return a > b ? a : b;
    }
    #include <deque>
    
    struct Petrol {
        double cost, volume;
    };
    
    deque<Petrol> dq;
    double dis[17], price[17];
    
    int main() {
    FileOpen();
    
    	double totDis, fuelMax, dx;
    	int n;
        scanf("%lf%lf%lf%lf%d", &totDis, &fuelMax, &dx, &price[0], &n);
        R(i,1,n){
            scanf("%lf%lf", &dis[i], &price[i]);
            if(dis[i] - dis[i - 1] > fuelMax * dx){
                printf("No Solution
    ");
                return 0;
            }
        }
        
        dis[n+1] = totDis;
        double fuelNow = fuelMax;
        dq.push_back((Petrol){price[0], fuelMax});
        double ans = price[0] * fuelMax;
        R(i,1,i + 1){
            double costFuel = (dis[i] - dis[i - 1]) / dx;
            while(!dq.empty() && costFuel > 0){
                Petrol x = dq.front(); dq.pop_front();
                if(x.volume > costFuel){
                    fuelNow -= costFuel;
                    dq.push_front((Petrol){x.cost, x.volume - costFuel});
                    break;
                }
                fuelNow -= x.volume;
    			costFuel -= x.volume;
            }
            
            if(i == n + 1){
                while(!dq.empty()) {
                    ans -= dq.front().cost * dq.front().volume;
                    dq.pop_front();
                }
                break;
            }
            
            while(!dq.empty() && dq.back().cost > price[i]){
                ans -= dq.back().cost * dq.back().volume;
                fuelNow -= dq.back().volume;
                dq.pop_back();
            }
            
            ans += (fuelMax - fuelNow) * price[i];
            dq.push_back((Petrol){price[i], fuelMax - fuelNow});
            fuelNow = fuelMax;
        }
        
        printf("%.2lf
    ", ans);
        return 0;
    }
    
  • 相关阅读:
    oracle sql日期比较
    rlwrap真是一个好东西
    Dataguard 归档丢失处理
    oracle latch工作原理
    Latch free等待事件
    Redhat Enterprise Linux 5 安装 Oracle 10g release 2
    oracle 日期问题
    Oracle自动存储管理 ASMLib的支持变化
    [官方文档] oracle官方文档总汇(9i,10g,11gR1, 11gR2)
    实时分布式搜索引擎比较(senseidb、Solr、elasticsearch)
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11437418.html
Copyright © 2020-2023  润新知