Schedule
来源:互联网 发布:淘宝产品为什么下架了 编辑:程序博客网 时间:2024/05/18 01:31
HDU - 6180
显然是先排序,然后按左端点从小到大放进去,每次在剩余的机子中找一个符合条件而且尽量大的。
但是一开始用 multiset 和 lowerbound 来进行处理会超时,就想到另一种写法。用一个优先队列和一个栈,对于当前任务,先将优先队列的所有合法情况按顺序压到栈中,直到不存在合法的机器,然后从栈找是否有满足条件的,如果没有就要增加机器
#include <bits/stdc++.h>using namespace std;int n;typedef long long ll;priority_queue<int, vector<int>, greater<int> > q;stack<int> s;const int ARS = 100010;void readnum(int &x) { x = 0; char c; for(c=getchar();c!=EOF && !isdigit(c);c=getchar()); for(;isdigit(c);c=getchar()) { x = 10*x + c-'0'; }}struct term{ int x, y; bool operator<(const term &rhs) const { return x < rhs.x; }} a[ARS];int main() { int _t; readnum(_t); while (_t--) { readnum(n); while (q.size()) q.pop(); while (s.size()) s.pop(); for (int i = 1; i <= n; i++) { readnum(a[i].x); readnum(a[i].y); } sort(a+1, a+n+1); ll bg = 0; ll ed = 0; int num = 0; for(int i = 1; i <= n; i++) { while(q.size() && q.top() <= a[i].x ) { s.push(q.top()); q.pop(); } if(s.empty()) { num++; q.push(a[i].y); bg += a[i].x; } else { s.pop(); q.push(a[i].y); } } while(q.size()) { ed += q.top(); q.pop(); } while(s.size()) { ed += s.top(); s.pop(); } printf("%d %lld\n", num, ed-bg); } return 0;}
阅读全文
0 0
- Schedule
- schedule
- schedule
- schedule()
- schedule
- schedule
- Schedule
- Schedule
- 【Course Schedule】Course Schedule
- Backup Schedule
- Timer.schedule()
- MGOS schedule
- PhD Schedule
- Task Schedule
- Vaccination schedule
- Study Schedule
- linux schedule
- schedule函数
- 配置文件解读 http://blog.csdn.net/maweifei/article/details/52965523
- sparkSQL官网简单解析
- Javaweb学习总结(三)
- 最大似然,贝叶斯,最大后验
- PEP 328
- Schedule
- 1321:棋盘问题
- 【搜狐笔试题】产品包装
- Python 3实现k-邻近算法以及 iris 数据集分类应用
- 正则表达式整理
- java解析HL7协议报文工具(v24版)
- Window下python 2.73安装pip
- Directx9学习(八)初识texture(3)
- haoi2013软件安装解题报告