2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) G 优先队列
2 seconds
512 megabytes
standard input
standard output
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 days x, 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 integers si, 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.
3
9 2
7 3
2 4
9 10
1 3
4 7
4
1000000000 1000000
1000000000 1000000
100000000 1000000
1000000000 1000000
1000000000 1000999999
1 1000000
100000000 100999999
1000001 2000000 题意:n个要求 给出期望起始时间以及持续时间 若期望的时间段空闲 则安排当前要求 在这个时间段 否则从1开始向后寻找一个合适的
空闲时间段 安排当前要求。输出n个要求的 时间段。
题解:可能写复杂了,优先队列处理。
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
#define A first
#define B second
const int mod=;
const int MOD1=;
const int MOD2=;
const double EPS=0.00000001;
typedef __int64 ll;
const ll MOD=;
const int INF=;
const ll MAX=1ll<<;
const double eps=1e-;
const double inf=~0u>>;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
int n;
ll s[];
ll d[];
struct node
{ ll l,r;
friend bool operator < (node a, node b)
{
return a.l > b.l;
}
} now;
priority_queue<node> pq;
queue<node> exm;
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%I64d %I64d",&s[i],&d[i]);
d[i]=s[i]+d[i]-;
}
now.l=;
now.r=s[]-;
if(now.l<=now.r)
pq.push(now);
now.l=d[]+;
now.r=;
pq.push(now);
for(int i=; i<=n; i++)
{
int flag=;
while(!exm.empty())
{
now=exm.front();
pq.push(now);
exm.pop();
}
while(!pq.empty())
{
now=pq.top();
pq.pop();
if(d[i]<=now.r&&s[i]>=now.l)
{
ll gg=now.r;
now.r=s[i]-;
if(now.l<=now.r)
pq.push(now);
now.r=gg;
now.l=d[i]+;
if(now.l<=now.r)
pq.push(now);
flag=;
break;
}
else
{
exm.push(now);
}
}
while(!exm.empty())
{
now=exm.front();
pq.push(now);
exm.pop();
}
if(flag==)
{
while(!pq.empty())
{
now=pq.top();
pq.pop();
if((d[i]-s[i])<=(now.r-now.l))
{
d[i]=now.l+d[i]-s[i];
s[i]=now.l;
if(d[i]<now.r)
now.l=d[i]+;
pq.push(now);
break;
}
else
{
exm.push(now);
}
}
}
}
for(int i=; i<=n; i++)
printf("%I64d %I64d\n",s[i],d[i]);
return ;
}
2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) G 优先队列的更多相关文章
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution
从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...
- Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结
第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...
- codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解
秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...
- 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)
i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution
A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest
目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...
- Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest
2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror) in codeforces(codeforces730)
A.Toda 2 思路:可以有二分来得到最后的数值,然后每次排序去掉最大的两个,或者3个(奇数时). /************************************************ ...
- 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing
[链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...
随机推荐
- WCF如何通过契约加编码方式调用
WCF采用基于契约的服务调用方法,通过System.ServiceModel.ChannelFactory<TChannel>直接创建服务代理对象. 创建服务代理 public stati ...
- Oracle、Mysql、Sql Server语句的区别
1.空值的处理——判断是否为空,为空时取一个值,不为空时取另一个值 1).Sql Server 中 ISNULL(check_expression,replacement_value) 解释:如果ch ...
- html中offsetTop、clientTop、scrollTop、offsetTop
HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth scrollHeight: 获取对象的滚动高度. scrollLeft:设置或获取位于对 ...
- Rhel6-heartbeat配置文档
系统环境: rhel6 x86_64 iptables and selinux disabled 主机: 192.168.122.119 server19.example.com 192.168.12 ...
- Rhel6-mailsystem配置文档
(postfix+dovecot+mysql+extmail) 理论基础:
- Asp.net项目因Session阻塞导致页面打开速度变慢
发现罪魁祸首是Session阻塞造成的.默认情况下session状态是“可写状态”(EnableSessionState=”true”),即当用户打开任何一个页面时,该页面的Session就会持有一个 ...
- git命令学习用
- Struts2 validate校验
一般的,用户注册的时候,我们需要校验一些用户提交过来的参数. 一般有两道屏障,一是在前台页面上使用js进行验证,直接杜绝了不正常信息的提交.二是将提交过来的信息进行验证,不通过则返回注册页面并显示错误 ...
- HTML5实战教程———开发一个简单漂亮的登录页面
最近看过几个基于HTML5开发的移动应用,比如臭名昭著的12036移动客户端就是主要使用HTML5来实现的,虽然还是有点反应迟钝,但已经比较流畅了,相信随着智能手机的配置越来越高性能越来越好,会越来越 ...
- UVa 10328 - Coin Toss (递推)
题意:给你一个硬币,抛掷n次,问出现连续至少k个正面向上的情况有多少种. 原题中问出现连续至少k个H的情况,很难下手.我们可以试着将问题转化一下. 设dp[i][j]表示抛掷i个硬币出现连续至多j个H ...