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;
    }
    
  • 相关阅读:
    HTML框架
    HTML链接
    kzalloc 函数详解(转载)
    LCD接口(转载)
    S3C2440上RTC时钟驱动开发实例讲解(转载)
    PHP 真值与空值
    http chunked 理解
    c# 基础
    美式音标注意事项
    groovy 闭包
  • 原文地址:https://www.cnblogs.com/wsmrxc/p/9419798.html
Copyright © 2011-2022 走看看