Codeforces 730G. Car Repair Shop 【map】
来源:互联网 发布:湖南广电网络官网 编辑:程序博客网 时间:2024/05/17 18:04
Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing, so he has already collected n requests from clients. The requests are numbered from 1 to n in order they came.
The i-th request is characterized by two values: si — the day when a client wants to start the repair of his car, di— duration (in days) to repair the car. The days are enumerated from 1, the first day is tomorrow, the second day is the day after tomorrow and so on.
Polycarp is making schedule by processing requests in the order from the first to the n-th request. He schedules the i-th request as follows:
- If the car repair shop is idle for di days starting from si (si, si + 1, ..., si + di - 1), then these days are used to repair a car of the i-th client.
- Otherwise, Polycarp finds the first day x (from 1 and further) that there are di subsequent days when no repair is scheduled starting from x. In other words he chooses the smallest positive x that all daysx, x + 1, ..., x + di - 1 are not scheduled for repair of any car. So, the car of the i-th client will be repaired in the range [x, x + di - 1]. It is possible that the day x when repair is scheduled to start will be less than si.
Given n requests, you are asked to help Polycarp schedule all of them according to the rules above.
The first line contains integer n (1 ≤ n ≤ 200) — the number of requests from clients.
The following n lines contain requests, one request per line. The i-th request is given as the pair of integerssi, di (1 ≤ si ≤ 109, 1 ≤ di ≤ 5·106), where si is the preferred time to start repairing the i-th car, di is the number of days to repair the i-th car.
The requests should be processed in the order they are given in the input.
Print n lines. The i-th line should contain two integers — the start day to repair the i-th car and the finish day to repair the i-th car.
39 27 32 4
9 101 34 7
41000000000 10000001000000000 1000000100000000 10000001000000000 1000000
1000000000 10009999991 1000000100000000 1009999991000001 2000000
AC代码:
#include<cstdio>#include<iostream>#include<map>#include<algorithm>using namespace std;typedef __int64 LL; int main(){map<LL,LL> M;int N;scanf("%d",&N);while(N--) {LL s,d,e;cin>>s>>d;e=s+d-1;map<LL ,LL>:: iterator it=M.lower_bound(s);if(it==M.end()||it->second>e) {printf("%I64d %I64d\n",s,e);M[e]=s; continue;}s=1;while(1){e=s+d-1;it=M.lower_bound(s);if(it==M.end()||it->second>e) {printf("%I64d %I64d\n",s,e);M[e]=s; break;}s=it->first+1;} }return 0;}
- Codeforces 730G. Car Repair Shop 【map】
- Codeforces 730G Car Repair Shop
- CodeForces 730G Car Repair Shop (优先队列乱搞)
- codeforces 730G Car Repair Shop 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest
- G. Car Repair Shop(优先队列)
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest G. Car Repair Shop(优先队列)
- 一个有趣的题目[CF730G|2016ACM NEERC G] Car Repair Shop
- Gym 100971G Repair
- RMRC2016 G:Flow Shop (DP)
- Thief in a Shop CodeForces
- POJ 3253 Fence Repair G++
- Codeforces 883G Orientation of Edges(BFS+MAP)
- 玲珑Round #4-G -- See car
- Codeforces 730G By Assassin
- Car
- Car
- Car
- Codeforces Round #521 D Shop 堆
- CentOS安装Node.js、Express和Socket.io
- C# 简单的 多线程 (3)
- 在dfs中传入List参数,所带来的引用bug
- 简单的ATM系统
- 拓扑排序问题(队列实现)
- Codeforces 730G. Car Repair Shop 【map】
- 常用设计模式汇总
- Servlet 异常处理
- ubuntu系统启动qtceator时提示:Qt5.5.1/Tools/QtCreator/lib/qtcreator/plugins/libHelp.so: 无法加载库
- 事务小例子-钱从哪里来?
- 编写函数,查看main函数中argv argc env函数的值
- iOS App组件化开发实践
- Total 多用途 WordPress主题 v3.4免费下载
- 在 CentOS7 上安装 MongoDB