hdu 6180 Schedule 贪心
来源:互联网 发布:院士 知乎 编辑:程序博客网 时间:2024/06/05 01:51
题目:
http://acm.hdu.edu.cn/showproblem.php?pid=6180
题意:
有n个任务,每个任务有一个开始时间s_i和结束时间e_i,在一些机器上执行任务,每个机器在一段时间间隔内只能执行一个任务,也就是允许时间点是重合的,在一个机器上执行的两个任务之间有段空闲时间的话,机器不能关闭。求最少需要多少台机器,然后求出在这些机器下执行完所以任务需要的最少时间
思路:
贪心选取,使空闲时间最小。如果当期任务跟其他任务都冲突,就增加一台机器
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int N = 100000 + 10;struct node{ int x, y;} a[N];bool cmp(node a,node b){ return a.x<b.x;}int main(){ int t, n; scanf("%d", &t); while(t--) { scanf("%d",&n); multiset<int>ste; for(int i = 1; i <= n; i++) scanf("%d%d",&a[i].x,&a[i].y); sort(a + 1, a + 1 + n, cmp); ll ans = 0; for(int i = 1; i <= n; i++) { auto p = ste.upper_bound(a[i].x); if(p == ste.begin())//跟之前的所有任务都冲突 { ans += a[i].y - a[i].x; ste.insert(a[i].y); } else { p--; ans += a[i].y - *p; ste.erase(p); ste.insert(a[i].y); } } printf("%d %I64d\n", ste.size(), ans); } return 0;}
阅读全文
0 0
- Hdu 6180 Schedule【贪心】
- hdu 6180 Schedule 贪心
- hdu 6180 Schedule 贪心
- hdu 6180 Schedule (贪心)
- hdu 6180 Schedule(贪心)
- hdu 6180 Schedule(贪心 multiset)
- hdu 6180 Schedule(贪心)
- HDU 6180 Schedule(贪心)
- HDU 6180 Schedule(贪心)
- hdu 6180 Schedule(贪心)
- 【多校训练】hdu 6180 Schedule 贪心+set
- 2017多校联合第十场/HDU 6180 Schedule (贪心)
- hdu-6180-Schedule
- HDU 6180 Schedule
- hdu 6180 Schedule
- HDU-6180 Schedule
- HDU 6180 Schedule
- HDU 6180 Schedule(水题)
- vue.js初学1
- c++11多线程的创建和unique_lock<mutex>的使用
- Logger日志库的基本使用
- layer.closeAll()无法关闭弹窗的解决办法之一
- [51nod-1563]坐标轴上的最大团
- hdu 6180 Schedule 贪心
- zookeeper单机单独实例安装-windows
- Idea中自动注释的缩进(避免添加注释自动到行首)
- 学完python写爬虫,不亦乐乎
- Android6.0之后动态权限申请
- A previous ephemeral live node still exists. Solr cannot continue. Please ensure that no other Solr
- 解决was8.5下自带log4j和slf4j的jar包与应用中jar包冲突问题
- css盒子模型
- POJ-2352 Stars (树状数组,离散,排序)