zoukankan      html  css  js  c++  java
  • P4266 [USACO18FEB]Rest Stops

    ##一眼过去

    什么都没想到
    认真分析了一下,觉得可能是个dp或者贪心。
    脑玩了一下,大概搞出来个贪心策略,就是直接选当前能选的最优选择就好,证明也很容易,反证即可
    还可以顺便证明草的tastiness 相同但地点不同时对权值贡献没有影响。
    贪心用堆维护就好

    #include <queue>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    const int MAXN = 1e5 + 20;
    typedef pair<int, int> P;
    typedef long long ll;
    inline int read()
    {
    	int x = 0; char ch = getchar(); bool f = false;
    	while(!isdigit(ch)) f |= (ch == '-'), ch = getchar();
    	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    	return f ? -x : x;
    }
    
    priority_queue<P> q; 
    int L, N, rf, rb;
    
    int main()
    {
    	cin>>L>>N>>rf>>rb;
    	for(int i = 1; i <= N; i++){
    		P pos;
    		pos.second = read(), pos.first = read();
    		q.push(pos);
    	}
    
    	int pb = 0; ll ans = 0;
    	while(!q.empty()){
    		P pos = q.top(); q.pop();
    		if(pos.second <= pb) continue;
    		ans += (1LL * rf - rb) * (1LL * pos.second - pb) * pos.first;
    		pb = pos.second;
    	}
    	cout<<ans<<endl;
    	return 0;
    }
    
  • 相关阅读:
    DDoS攻击
    CSRF攻击
    正向代理和反向代理
    DNS协议
    四次挥手
    Nginx重要概念之lingering_close
    Nginx重要概念之pipeline
    Nginx重要概念之keepalive
    http1.0、http1.1、http2.0三者的区别
    Vue axios封装二
  • 原文地址:https://www.cnblogs.com/wsmrxc/p/9419798.html
Copyright © 2011-2022 走看看