• Codeforces Round #523 (Div. 2) D. TV Shows 模拟(多重集 先把所有区间加入多重集合)+贪心+二分


    题意:给出n个电视节目的起始和结束时间  并且租一台电视需要x +y*(b-a)  【a,b】为时段

    问完整看完电视节目的最小花费是多少

    思路:贪心的思想 情况1 如果新租一台电视的花费<=在空闲电视上面看节目 那么肯定新租电视

            情况2 否则就直接在空闲电视上看 就好

    模拟难(QAQ): 这里使用多重集合模拟   先把所有时间的pair(结束时间,开始时间) 放入多重集里面

    然后开一个数组以l 从小到大排序

    从数组小到大 枚举  在多重集里面找离终点最近的那个点 如果符合情况1 那么就删去 找到的那个点即可(因为 刚开始多重集有所有的区间 所以不用添加)

          否则情况2 直接加上值即可

     1 #include<bits/stdc++.h>
     2 #define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;i++)
     3 #define MS(arr,arr_value) memset(arr,arr_value,sizeof(arr)) 
     4 #define F first 
     5 #define S second
     6 #define pii pair<int ,int >
     7 #define mkp make_pair
     8 #define pb push_back
     9 #define arr(zzz) array<ll,zzz>
    10 #define ll long long 
    11 using namespace std;
    12 const int maxn=1e6+100;
    13 const int inf=0x3f3f3f3f;
    14 const int mod=1e9+7;
    15 vector<pii>v;
    16 multiset<pii>s;
    17 int main(){
    18     int n,x,y;
    19     scanf("%d%d%d",&n,&x,&y);
    20     int a,b;
    21     for(int i=1;i<=n;i++)scanf("%d%d",&a,&b),v.pb({a,b}),s.insert({b,a});
    22     sort(v.begin(),v.end(),[](pii a,pii b){return a.F<b.F;});
    23      ll ans=0;
    24     for(int i=0;i<n;i++){
    25         ll tmp=x+1ll*y*(v[i].S-v[i].F);
    26         if(s.size()==0||(*s.begin()).F>=v[i].F){
    27             ans+=tmp;
    28             ans%=mod;
    29             continue;
    30         }
    31         multiset<pii>::iterator it=s.lower_bound({v[i].F,-1});
    32         it--;
    33         if(tmp<=1ll*y*(v[i].S-(*(it)).F)){
    34         ans+=tmp;    
    35         ans%=mod;
    36             continue;
    37         }
    38         ans+=1ll*y*(v[i].S-(*(it)).F);
    39         ans%=mod;
    40         s.erase(it);
    41     }
    42     cout<<ans<<endl;
    43     
    44     return 0;
    45 }
    View Code
  • 相关阅读:
    Educational Codeforces Round 13 E. Another Sith Tournament 概率dp+状压
    Codeforces Round #358 (Div. 2) D. Alyona and Strings 字符串dp
    Codeforces Round #359 (Div. 2) D. Kay and Snowflake 树的重心
    Codeforces Round #311 (Div. 2) D. Vitaly and Cycle 奇环
    Codeforces Round #Pi (Div. 2) E. President and Roads 最短路+桥
    Codeforces Gym 100342J Problem J. Triatrip 三元环
    HDU 4587 TWO NODES 割点
    hdu 5615 Jam's math problem(十字相乘判定)
    C++数组作为函数参数的几个问题(转)
    UVA
  • 原文地址:https://www.cnblogs.com/ttttttttrx/p/10791525.html
Copyright © 2020-2023  润新知