Statistics of Recompre…
2015-06-07 09:52
399 查看
Statistics of Recompressing Videos
Time
Limit:3000MS Memory
Limit:262144KB 64bit
IO Format:%I64d & %I64u
Submit Status Practice CodeForces
523D
Description
A social network for dogs called DH (DogHouse)
has k special
servers to recompress uploaded videos of cute cats. After each
video is uploaded, it should be recompressed on one (any) of the
servers, and only after that it can be saved in the social
network.
We know that each server takes one second to recompress a one
minute fragment. Thus, any server
takes m seconds
to recompress a mminute video.
We know the time when each of
the n videos
were uploaded to the network (in seconds starting from the moment
all servers started working). All videos appear at different
moments of time and they are recompressed in the order they appear.
If some video appeared at
time s, then its recompressing can start
at that very moment, immediately. Some videos can await
recompressing when all the servers are busy. In this case, as soon
as a server is available, it immediately starts recompressing
another video. The videos that await recompressing go in a queue.
If by the moment the videos started being recompressed some servers
are available, then any of them starts recompressing the video.
For each video find the moment it stops being recompressed.
Input
The first line of the input contains
integers n and k (1 ≤ n, k ≤ 5·105)
— the number of videos and servers, respectively.
Next n lines
contain the descriptions of the videos as pairs of
integers si, mi (1 ≤ si, mi ≤ 109),
where si is
the time in seconds when
the i-th video appeared
and mi is
its duration in minutes. It is guaranteed that all
the si's are distinct
and the videos are given in the chronological order of upload, that
is in the order of
increasing si.
Output
Print n numbers e1, e2, ..., en,
where ei is
the time in seconds after the servers start working, when
the i-th video will be
recompressed.
Sample Input
Input
Output
Input
Output
题目意思就是有一堆机器和一些工程,每个工程都有出现时间和完成它所需要的时间,求出每个工程最快完成的时间。题目中有一个明显的单词queue,因此用优先队列来进行维护。并且输入已经将序列排好,不解的是我的ide居然不能完成greater的函数。刚学习了队列,用的不是很熟,占了不少内存。中间也有不少废代码,可以消去。
Time
Limit:3000MS Memory
Limit:262144KB 64bit
IO Format:%I64d & %I64u
Submit Status Practice CodeForces
523D
Description
A social network for dogs called DH (DogHouse)
has k special
servers to recompress uploaded videos of cute cats. After each
video is uploaded, it should be recompressed on one (any) of the
servers, and only after that it can be saved in the social
network.
We know that each server takes one second to recompress a one
minute fragment. Thus, any server
takes m seconds
to recompress a mminute video.
We know the time when each of
the n videos
were uploaded to the network (in seconds starting from the moment
all servers started working). All videos appear at different
moments of time and they are recompressed in the order they appear.
If some video appeared at
time s, then its recompressing can start
at that very moment, immediately. Some videos can await
recompressing when all the servers are busy. In this case, as soon
as a server is available, it immediately starts recompressing
another video. The videos that await recompressing go in a queue.
If by the moment the videos started being recompressed some servers
are available, then any of them starts recompressing the video.
For each video find the moment it stops being recompressed.
Input
The first line of the input contains
integers n and k (1 ≤ n, k ≤ 5·105)
— the number of videos and servers, respectively.
Next n lines
contain the descriptions of the videos as pairs of
integers si, mi (1 ≤ si, mi ≤ 109),
where si is
the time in seconds when
the i-th video appeared
and mi is
its duration in minutes. It is guaranteed that all
the si's are distinct
and the videos are given in the chronological order of upload, that
is in the order of
increasing si.
Output
Print n numbers e1, e2, ..., en,
where ei is
the time in seconds after the servers start working, when
the i-th video will be
recompressed.
Sample Input
Input
3 2 1 5 2 5 3 5
Output
6 7 11
Input
6 1 1 1000000000 2 1000000000 3 1000000000 4 1000000000 5 1000000000 6 3
Output
1000000001 2000000001 3000000001 4000000001 5000000001 5000000004
题目意思就是有一堆机器和一些工程,每个工程都有出现时间和完成它所需要的时间,求出每个工程最快完成的时间。题目中有一个明显的单词queue,因此用优先队列来进行维护。并且输入已经将序列排好,不解的是我的ide居然不能完成greater的函数。刚学习了队列,用的不是很熟,占了不少内存。中间也有不少废代码,可以消去。
#include #include #include using namespace std; struct Video{ long long st; long long ed; long long id; bool operator <(const Video&a)const { return st + ed>a.ed + a.st; } }video[500005]; long long re[500005]; priority_queueq;
int main() { ios::sync_with_stdio(false); long long n, k, i, j, ans; cin >> n >> k; for (i = 1; i <= n; i++) { cin >> video[i].st >> video[i].ed; video[i].id = i; } re[1] = video[1].ed + video[1].st; q.push(video[1]); ans = 1; for (i = 2; i <= n; i++) { if (!q.empty()) { if (q.top().ed + q.top().st <= video[i].st) { re[i] = video[i].st + video[i].ed; q.pop(); } else { if (ans < k) { ans++; re[i] = video[i].st + video[i].ed; } else { video[i].st = q.top().st + q.top().ed; re[i] = video[i].st + video[i].ed; q.pop(); } } q.push(video[i]); } else { re[i] = video[i].st + video[i].ed; q.push(video[i]); ans++; } } for (i = 1; i <= n; i++) cout << re[i] << "\n"; return 0; }
相关文章推荐
- Packets
- ACdream的高速公路
- Protecting&nbsp;the&nbsp;Flowers
- Robbers
- hiho一下 第四十九周
- css中的relative(相对位置)和absolute(绝对位置)
- 全面SSH 远程操作与端口转发,远程copy
- dfsd
- 二进制暴力
- NYOJ 47 过河问题
- wamp 中安装cakephp Fatal error: You must enable the intl extension to use CakePHP. in XXX
- ASP.NET中集成百度编辑器UEditor
- C++模板中的静态
- 如何直接访问WEB-INF下列文件
- NGS项目四:高通量测序在植物生物胁迫研究中的应用
- Compiling... ,Error spawning cl.exe 解决方案——VC6环境变量配置
- 设计一个中间件的访问日志组件
- 折半查找
- python 2 给我自己看
- 设计一个中间件的访问日志组件