HDU 6180 Schedule
来源:互联网 发布:ci 数据库配置 编辑:程序博客网 时间:2024/06/05 09:21
题目地址
题意:有m个工程,一台机器在同一时间只能运行一个工程,告诉你每个工程的起始时间和结束时间,求出最少要多少个机器以及最小的机器总运行时间(机器开始了就不能停了,知道用完该台机器才停止)。
思路:先按起始时间排序,再用两个优先队列去维护(一个大的优先级更高用于空闲序列,一个小的优先级更高用于运行序列),然后直接模拟就好了,每次都先把运行序列中比当前开始时间小的弹出到空闲序列,再从空闲序列中找到一个时间最晚的加入运行序列(因为要总运行时间最小)。
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <stack>#include <cmath>#include <cstdio>#include <algorithm>#include <functional>#define N 100010#define LL __int64#define inf 0x3f3f3f3f#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1#define getMid (l+r)>>1#define movel ans<<1#define mover ans<<1|1using namespace std;const LL mod = 1e9 + 7;struct node { LL st, en;}thing[N];bool cmp1(node a, node b) { if (a.st == b.st) { return a.en < b.en; } return a.st < b.st;}int main() { cin.sync_with_stdio(false); int T; int n; cin >> T; while (T--) { cin >> n; priority_queue<LL>p;//空闲集合 priority_queue<LL, vector<LL>, greater<LL> >q;//工作集合 for (int i = 0; i < n; i++) { cin >> thing[i].st >> thing[i].en; } LL ans = 0, sum = 0; sort(thing, thing + n, cmp1); for (int i = 0; i < n; i++) { node now = thing[i]; while ((!q.empty()) && q.top() <= now.st) { p.push(q.top()); q.pop(); } if (!p.empty()) { int num = p.top(); p.pop(); sum += now.en - num; q.push(now.en); } else { ans++; sum += now.en - now.st; q.push(now.en); } } cout << ans << " " << sum << endl; } return 0;}
阅读全文
0 0
- hdu-6180-Schedule
- HDU 6180 Schedule
- Hdu 6180 Schedule【贪心】
- hdu 6180 Schedule
- HDU-6180 Schedule
- 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(贪心 multiset)
- hdu 6180 Schedule(贪心)
- HDU 6180 Schedule(贪心)
- HDU 6180 Schedule(贪心)
- hdu 6180 Schedule(贪心)
- HDU 6180 Schedule (扫描线 化线成点)
- Unity3D发布WebGL(网页)到IIS服务器并加入ASP.NET页面中
- 基于spark的网络爬虫实现
- AngularJS实战之filter的使用二
- c++ 中缀表达式转后缀表达式 计算器
- C++11中的匿名函数(lambda函数,lambda表达式)
- HDU 6180 Schedule
- crypto++ User Guide: filters.h学习笔记
- Spring Boot 定时任务之Quartz
- linux 字符设备入门学习笔记
- 【redis】RDB 持久化
- 【USACO3.3.5】游戏(区间dp的滚动数组与编码问题)
- Sparkler:Spark上的爬虫
- 【Linux学习笔记】10:帮助命令man
- 集合