hdu 6180
来源:互联网 发布:vb.net 多行注释 编辑:程序博客网 时间:2024/06/18 09:03
题解:按开始工作的时间从小到大排序后,用一个set容器维护一下,每次加入找set里面结束时间小于等于开始时间并且最近的点插入即可,然后如果没有小于开始时间的就重新开一台机器即可
- #include<iostream>
- #include<cstring>
- #include<algorithm>
- #include<cstring>
- #include<set>
- using namespace std;
- typedef long long int ll;
- const int mx = 1e5+5;
- struct node{
- int s,e;
- }a[mx];
- bool cmp(node a,node b){
- return a.s<b.s;
- }
- multiset<int>st;
- int main(){
- int t,n;
- scanf("%d",&t);
- while(t--){
- scanf("%d",&n);
- st.clear();
- for(int i = 0; i < n; i++)
- scanf("%d%d",&a[i].s,&a[i].e);
- sort(a,a+n,cmp);
- ll ans = 0;
- for(int i = 0; i < n; i++){
- auto it = st.upper_bound(a[i].s);
- if(it==st.begin()){
- ans += a[i].e-a[i].s;
- st.insert(a[i].e);
- }
- else{
- it--;
- ans += a[i].e-*it;
- st.erase(it);
- st.insert(a[i].e);
- }
- }
- printf("%d %I64d\n",st.size(),ans);
- }
- return 0;
- }
阅读全文
0 0
- hdu 6180
- hdu-6180-Schedule
- HDU 6180 贪心记录
- HDU 6180 Schedule
- hdu 6180 贪心+multiset
- Hdu 6180 Schedule【贪心】
- hdu 6180 Schedule
- HDU-6180 Schedule
- HDU 6180 Schedule
- hdu 6180 Schedule 贪心
- hdu 6180 Schedule 贪心
- HDU 6180 Schedule(水题)
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- struts2获取ServletAPI
- python实践小程序
- 根据先序序列与中序序列构建二叉树
- c#Invoke和BeginInvoke的区别
- 漏洞银行/逆向工程学习日记(4)-跳转指令&指令跳转原理
- hdu 6180
- opengl相关学习资料
- Python dataframe.pivot()
- kali2.0的ssh
- Oracle 内存里的 SGA是如何构成的呢又起到什么作用
- 发送post请求到https的url
- angularJS-打开新的标签页
- python 给定数字,使表达式 = 固定值
- 微机硬件接口 提纲挈领