B. The Queue----思维题
来源:互联网 发布:windows rt能换系统吗 编辑:程序博客网 时间:2024/04/29 04:49
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow.
He knows that the receptionist starts working after ts minutes have passed after midnight and closes after tf minutes have passed after midnight (so that (tf - 1) is the last minute when the receptionist is still working). The receptionist spends exactly t minutes on each person in the queue. If the receptionist would stop working within t minutes, he stops serving visitors (other than the one he already serves).
Vasya also knows that exactly n visitors would come tomorrow. For each visitor Vasya knows the point of time when he would come to the passport office. Each visitor queues up and doesn't leave until he was served. If the receptionist is free when a visitor comes (in particular, if the previous visitor was just served and the queue is empty), the receptionist begins to serve the newcomer immediately.
For each visitor, the point of time when he would come to the passport office is positive. Vasya can come to the office at the time zero (that is, at midnight) if he needs so, but he can come to the office only at integer points of time. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and stand in the queue after the last of them.
Vasya wants to come at such point of time that he will be served by the receptionist, and he would spend the minimum possible time in the queue. Help him!
The first line contains three integers: the point of time when the receptionist begins to work ts, the point of time when the receptionist stops working tf and the time the receptionist spends on each visitor t. The second line contains one integer n — the amount of visitors (0 ≤ n ≤ 100 000). The third line contains positive integers in non-decreasing order — the points of time when the visitors arrive to the passport office.
All times are set in minutes and do not exceed 1012; it is guaranteed that ts < tf. It is also guaranteed that Vasya can arrive at the passport office at such a point of time that he would be served by the receptionist.
Print single non-negative integer — the point of time when Vasya should arrive at the passport office. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and queues up the last. If there are many answers, you can print any of them.
10 15 2210 13
12
8 17 343 4 5 8
2
In the first example the first visitor comes exactly at the point of time when the receptionist begins to work, and he is served for two minutes. At 12 minutes after the midnight the receptionist stops serving the first visitor, and if Vasya arrives at this moment, he will be served immediately, because the next visitor would only come at 13 minutes after midnight.
In the second example, Vasya has to come before anyone else to be served.
题目链接:http://codeforces.com/contest/767/problem/B
比赛卡了我一个小时50分钟,我想麻烦了,借鉴柏皓的思路,补了一发,这个思路确实简单。
题目的意思是说,有个人需要办理一个证件,证件办理处开门的时间是ta到tb,办理一个证件需要t的时间,现在有n个人,知道n个人来的时间,求这个办理证件的人在什么时间来等待的时间最少。
注意坑点,若最后一个不足t,则不办理,比如7 14 3 2 1 2 不能输出13,因为从13开始办理时间不足t,题目中直说办理的,我被坑在了这里,注意long long 。
柏皓的思路很简洁,因为是非递减输入,对于每个输入我们进行”试插”,即在a-1和a+1两个地方试试。
代码:
#include <cstdio>#include <cstring>#include <iostream>using namespace std;int main(){ long long a,b,t; long long m=1e12+10; cin>>a>>b>>t; int n; cin>>n; long long ans=0; while(n--){ long long k; cin>>k; if(k<=b-t){//注意判断输入数据合法 if(k&&max(a,k-1)<=b-t&&(a-k+1)<m){ m=a-k+1;//需要等待的最小时间 ans=min(a,k-1); } a=max(a,k)+t; } } if(a<=b-t){//这样就可以不用等待 ans=a; } cout<<ans<<endl; return 0;}
- B. The Queue----思维题
- (思维题)Codeforces Round #398 B. The Queue
- B. The Queue
- B. The Queue codeforces398div2
- B. Queue at the School
- Codeforces 767 B The Queue
- CF #398B The Queue
- CodeForces 767B The Queue
- codeforce 558B Amr and The Large Array 思维题
- 266B - Queue at the School
- CodeForces-266B Queue at the School
- ACJoy B Queue at the School
- Codeforces Round #398 B. The Queue
- Codeforces 767"B" The Queue 模拟
- codeforces 767 b The Queue(模拟)
- codeforces 767B The Queue【贪心】
- codeforces 266B Queue at the School
- CF 266B Queue at the School (人生第一道B题)
- R语言入门
- Django学习:URL配置方法(3)
- ***SPOJ - GCJ1C09C Bribe the Prisoners【贿赂囚犯】
- FactoryBean的使用
- centos 下mysql怎么开启服务
- B. The Queue----思维题
- 下载安装mysql
- bzoj 1115 阶梯博弈
- oj1948: C语言实验——交换两个整数的值(顺序结构)
- PAT 1019 数字黑洞
- 高数Umaru系列(3)——喵星人
- 阿里云centos开启ipv6支持
- 安装ubuntu14.04遇到网卡驱动不成功问题
- 欢迎使用CSDN-markdown编辑器