A
来源:互联网 发布:盾太脸型数据 编辑:程序博客网 时间:2024/06/15 17:11
题意: 有若干个人的请求,有无数台机器,每个机器隔K秒就会自锁。询问如何安排才可以让这些人使用机器时,需要解锁的次数最少。
输出节省的时间!!!
思路:
对于每个人的请求找到当前set里面最小的时间+k,如果可以则更改,若当前的时间比最小的时间+k都大,那么这个机器必定会锁上,set弹出。
set里存放的是当前工作的人离开的时间
#include <iostream>#include <cstring>#include <set>#include <algorithm>using namespace std;const int maxn = 300005;struct node{ int st, ed; bool friend operator < (node a, node b) { return a.st < b.st; }} nod[maxn];int main(){ ios::sync_with_stdio(false); int n, m; cin>>n>>m; for(int i=1; i<=n; ++i) cin>>nod[i].st>>nod[i].ed; sort(nod+1, nod+1+n); multiset<int> st; multiset<int>::iterator it; int ans = 0; for(int i=1; i<=n; ++i) { int stat = nod[i].st - m; while(st.size() && *st.begin() < stat) st.erase(st.begin()); if(st.size() && *st.begin() <= nod[i].st) st.erase(st.begin()); else ans ++; st.insert(nod[i].st+nod[i].ed); } cout<<n-ans<<endl; return 0;}
阅读全文
0 0
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- A
- A*
- a
- A
- a
- RecordRTC 打开设备录像并压缩文件
- RabbitMQ管理(2)——用户管理
- poj3169(差分约束系统)
- 关于Target runtime com.genuitec.runtime.generic.jee60 is not defined问题的解决办法
- ProxySG 对URL中Query部分的定义
- A
- Python学习笔记: Python3中map、filter、reduce函数
- linux下sftp常用命令
- 关于信息熵与期望的关系的个人理解
- qt获取窗口句柄来显示图片
- git常用命令总结(分类)
- 生产环境的Hadoop版本比较
- 【机器学习实战】第8章 预测数值型数据:回归(Regression)
- 9