Codeforces Round #523 (Div. 2) D. TV Shows 模拟(多重集 先把所有区间加入多重集合)+贪心+二分
题意:给出n个电视节目的起始和结束时间 并且租一台电视需要x +y*(b-a) 【a,b】为时段
问完整看完电视节目的最小花费是多少
思路:贪心的思想 情况1 如果新租一台电视的花费<=在空闲电视上面看节目 那么肯定新租电视
情况2 否则就直接在空闲电视上看 就好
模拟难(QAQ): 这里使用多重集合模拟 先把所有时间的pair(结束时间,开始时间) 放入多重集里面
然后开一个数组以l 从小到大排序
从数组小到大 枚举 在多重集里面找离终点最近的那个点 如果符合情况1 那么就删去 找到的那个点即可(因为 刚开始多重集有所有的区间 所以不用添加)
否则情况2 直接加上值即可
#include<bits/stdc++.h>
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;i++)
#define MS(arr,arr_value) memset(arr,arr_value,sizeof(arr))
#define F first
#define S second
#define pii pair<int ,int >
#define mkp make_pair
#define pb push_back
#define arr(zzz) array<ll,zzz>
#define ll long long
using namespace std;
const int maxn=1e6+;
const int inf=0x3f3f3f3f;
const int mod=1e9+;
vector<pii>v;
multiset<pii>s;
int main(){
int n,x,y;
scanf("%d%d%d",&n,&x,&y);
int a,b;
for(int i=;i<=n;i++)scanf("%d%d",&a,&b),v.pb({a,b}),s.insert({b,a});
sort(v.begin(),v.end(),[](pii a,pii b){return a.F<b.F;});
ll ans=;
for(int i=;i<n;i++){
ll tmp=x+1ll*y*(v[i].S-v[i].F);
if(s.size()==||(*s.begin()).F>=v[i].F){
ans+=tmp;
ans%=mod;
continue;
}
multiset<pii>::iterator it=s.lower_bound({v[i].F,-});
it--;
if(tmp<=1ll*y*(v[i].S-(*(it)).F)){
ans+=tmp;
ans%=mod;
continue;
}
ans+=1ll*y*(v[i].S-(*(it)).F);
ans%=mod;
s.erase(it);
}
cout<<ans<<endl; return ;
}
Codeforces Round #523 (Div. 2) D. TV Shows 模拟(多重集 先把所有区间加入多重集合)+贪心+二分的更多相关文章
- Codeforces Round #523 (Div. 2) D. TV Shows
传送门 https://www.cnblogs.com/violet-acmer/p/10005351.html 题意: 有n个节目,每个节目都有个开始时间和结束时间. 定义x,y分别为租电视需要的花 ...
- Codeforces Round #523 (Div. 2)
Codeforces Round #523 (Div. 2) 题目一览表 来源 考察知识点 完成时间 A Coins cf 贪心(签到题) 2018.11.23 B Views Matter cf 思 ...
- Codeforces Round #368 (Div. 2) B. Bakery (模拟)
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...
- Codeforces Round #523 (Div. 2) Solution
A. Coins Water. #include <bits/stdc++.h> using namespace std; int n, s; int main() { while (sc ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序
A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #523 (Div. 2) E. Politics(最小费+思维建图)
https://codeforces.com/contest/1061/problem/E 题意 有n个点(<=500),标记第i个点的代价a[i],然后分别在这n个点建两棵树,对于每颗树的每个 ...
- Codeforces Round #523 (Div. 2) F. Katya and Segments Sets (交互题+思维)
https://codeforces.com/contest/1061/problem/F 题意 假设存在一颗完全k叉树(n<=1e5),允许你进行最多(n*60)次询问,然后输出这棵树的根,每 ...
- Codeforces Round #523 (Div. 2) Cdp
题:https://codeforces.com/contest/1061/problem/C 题意:给你一个序列,我们求他们子序列的个数,这个子序列有个限制就是每一个子序列上的值都必须是能整除他的下 ...
随机推荐
- .net core中使用autofac进行IOC
.net Core中自带DI是非常简单轻量化的,但是如果批量注册就得扩展,下面使用反射进行批量注册的 public void AddAssembly(IServiceCollection servic ...
- jQuery(二)、选择器
1.#id 根据给定的ID匹配一个元素,如果选择器中包含特殊字符,可以用双斜杆(\\) 转义 如: 查找ID 为 myDiv[bar] 的元素 HTML 代码: <div id="no ...
- h5页面 video暂停播放 视频控件 以及当前页面只有一个可以播放效果
<!DOCTYPE html> <html> <head> <meta name="viewport" content="wid ...
- vue-router 通过路由来实现切换头部标题
在做单页面应用程序时,一般页面布局头尾两块都是固定在布局页面,中间为是路由入口.这时访问页面时头部标题不会变,该问题的解决方案如下: 通过采用组件内路由卫士(beforeRouterEnter.bef ...
- Python笔记-面向对象编程
1.类和实例 面向-对象的三大特点:数据封装.继承和多态 在Python中,所有数据类型都可以视为对象,当然也可以自定义对象.自定义的对象数据类型就是面向对象中的类(Class)的概念. 假设我们要处 ...
- 关于Android Studio 3.2 运行应用时提示 “Instant Run requires that the platform corresponding to your target device (Android 7.0 (Nougat)) is installed.” 的说明
点击"Run",运行App后,Android Studio显示如图1-1界面: 图1-1 这是因为你连接的外部设备(比如Android手机或AVD)的SDK版本在你的电脑上没有安装 ...
- dede首页、列表页调用非缩略图
在include/extend.func.php末尾添加 function firstimg($str_pic) { $str_sub=substr($str_pic,0,-7).strrchr($s ...
- Unity切换到安卓平台Shader丢失(opengl)
Unity安卓平台shader平台丢失 Unity的工程切换到Android平台后,运行游戏出现shader丢失 解决办法:在Unity桌面图标的快捷方式后添加 -force-gles20 示例:&q ...
- C# -- 使用线程池 ThreadPool 执行多线程任务
C# -- 使用线程池 ThreadPool 执行多线程任务 1. 使用线程池 class Program { static void Main(string[] args) { WaitCallba ...
- Centos7安装搜狗输入法.
系统默认安装输入法管理器的是 ibus. 而搜狗使用 fcitx 1.以我们先要安装 fcitx和必要的软件包 yum -y install fcitx* yum -y install libQtWe ...