hdu6180Schedule(第十场贪心)
来源:互联网 发布:php 开源 客服系统 编辑:程序博客网 时间:2024/06/10 22:17
Schedule
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 153428/153428 K (Java/Others)Total Submission(s): 878 Accepted Submission(s): 339
Problem Description
There are N schedules, the i-th schedule has start time si and end time ei (1 <= i <= N). There are some machines. Each two overlapping schedules cannot be performed in the same machine. For each machine the working time is defined as the difference between timeend and timestart , where time_{end} is time to turn off the machine and timestart is time to turn on the machine. We assume that the machine cannot be turned off between the timestart and the timeend .
Print the minimum number K of the machines for performing all schedules, and when only uses K machines, print the minimum sum of all working times.
Print the minimum number K of the machines for performing all schedules, and when only uses K machines, print the minimum sum of all working times.
Input
The first line contains an integer T (1 <= T <= 100), the number of test cases. Each case begins with a line containing one integer N (0 < N <= 100000). Each of the next N lines contains two integers si and ei (0<=si<ei<=1e9) .
Output
For each test case, print the minimum possible number of machines and the minimum sum of all working times.
Sample Input
131 34 62 5
Sample Output
2 8
Source
2017 Multi-University Training Contest - Team 10
给你n个计划,要求用最少的机器解决完计划。机器不能在重叠的计划内工作,求花费的总时间。
思路:将所有的计划按开始时间排序好,用upper_bound函数,如果队列中有大于新加入的开始时间时,更新,如果没有,继续加入新的结束时间
按例中:排好序为(1,3)(2,5)(4,6),新加入3入队,判断第二次的新加入为2,队首大于2所以直接加入5,再加入4,队列中第二个大于4,所以去掉队首3,更新为5,队尾更新为6,最后统计节点为5,6两个
#include <bits/stdc++.h>#define LL long longusing namespace std;const int N = 1e5+7;int n;struct node{ int l,r;} p[N];int cmp(node a,node b){ return a.l<b.r;}multiset<int>S;int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d",&n); S.clear(); for(int i=0;i<n;i++) { scanf("%d %d",&p[i].l,&p[i].r); } sort(p,p+n,cmp); LL ans=0; for(int i=0;i<n;i++) { multiset<int>:: iterator it=S.upper_bound(p[i].l); if(it==S.begin()) { ans+=p[i].r-p[i].l; //cout<<ans<<endl; //cout<<p[i].r<<endl; S.insert(p[i].r); } else { it--; ans+=p[i].r-*it; //cout<<ans<<endl; S.erase(*it); //cout<<p[i].r<<endl; S.insert(p[i].r); } } printf("%d %lld\n",S.size(),ans); /*for(multiset<int>:: iterator it=S.begin();it!=S.end();it++) { cout<<*it<<endl; }*/ } return 0;}
阅读全文
0 0
- hdu6180Schedule(第十场贪心)
- hdu6180Schedule-(贪心)
- hdu6180Schedule(贪心+set)
- HDU6180Schedule(贪心)
- hdu6180Schedule
- 2017多校联合第十场/HDU 6180 Schedule (贪心)
- HDU 6180 Schedule(任务调度 贪心策略 17多校第十场)
- 多校第十场
- HDU4705-杭电多校第十场1010
- HDU4696-杭电多校第十场1001
- HDU4699-杭电多校第十场1004
- 多校比赛第十场
- 多校联赛第十场
- Multi-university 第十场 经验总结
- acm个人赛第十场成绩
- hdu 4705 Y 多校第十场
- hdu 4704 Sum 多校第十场
- HDU4701-杭电多校第十场1006-博弈
- softmax回归详解【转载】
- 分享一个bat脚本,比较文件输出是否相同,并输出第一个不同的位置
- 4078:实现堆结构
- 简单CrackMe分析(样本名:ReverseMe)
- 一个在线音乐软件的故事(五、让我们开始写代码吧)
- hdu6180Schedule(第十场贪心)
- 面试干货!21个必知数据科学面试题和答案part1(1-11)
- 如何让Maya中的相机和Unity相机的FOV(Angle of View)对上
- 蓝牙通信
- RN实现TabNavigator
- Linux下的rpm软件管理(管理软件的卸载、安装、更新)
- java二维码工具类:生成二维码和解析二维码
- Ubuntu配置Django+ Apache2+ mysql
- ajax 异步请求 async:true;// true为异步,默认异步,false为同步