Codeforces 767B. The Queue 模拟题
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.
"Reception 1"
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 2
2
10 13
12
8 17 3
4
3 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
题意:接待员的工作时间,结束时间,处理每个人的时间分别为ts,tf,t。现在有n个人明天将到达窗口的时间x[1],x[2]...x[n],,问明天什么时候去排队等待的时间最少。如果和某一个人同时到达,排在这个人的后面。数据保证答案可以买到票。
思路:模拟题。排在i-1~i人之间。比较x[i-1],x[i]-1与处理完i-1人的时候的时间sign进行比较。
代码:
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN=1e5+,INF=0x3f3f3f3f,MOD=1e9+;
ll x[MAXN];
int main()
{
ll ts,tf,t;
scanf("%lld%lld%lld",&ts,&tf,&t);
int n;
scanf("%d",&n);
for(int i=; i<=n; i++) scanf("%lld",&x[i]);
x[]=,x[n+]=tf+;
ll sign=ts;
ll Min=tf,ans=-;
for(int i=; i<=n+; i++)
{
if(sign>tf-t) break;
if(x[i-]==x[i]) {sign+=t;continue;}
///x[i-1]~x[i]-1;
if(x[i-]>sign)
{
if(x[i-]-sign<Min)
Min=x[i-]-sign,ans=x[i-];
}
else if(x[i]-<sign)
{
if(sign-(x[i]-)<Min)
Min=sign-(x[i]-),ans=x[i]-;
}
else
{
cout<<sign<<endl;
return ;
}
sign+=t;
}
cout<<ans<<endl;
return ;
}
Codeforces 767B. The Queue 模拟题的更多相关文章
- CodeForces 767B The Queue
模拟. 情况有点多,需要仔细.另外感觉题目的$tf$有点不太对......而且数据水了. $0$ $5$ $2$ $2$ $0$ $5$ 这组数据按照题意的话答案可以是$2$和$4$,但是好多错的答案 ...
- CodeForces - 344D Alternating Current (模拟题)
id=46667" style="color:blue; text-decoration:none">CodeForces - 344D id=46667" ...
- Codeforces 691C. Exponential notation 模拟题
C. Exponential notation time limit per test: 2 seconds memory limit per test:256 megabytes input: st ...
- CodeForces - 344B Simple Molecules (模拟题)
CodeForces - 344B id=46665" style="color:blue; text-decoration:none">Simple Molecu ...
- CodeForces - 344E Read Time (模拟题 + 二分法)
E. Read Time time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- CodeForces 681C Heap Operations (模拟题,优先队列)
题意:给定 n 个按顺序的命令,但是可能有的命令不全,让你补全所有的命令,并且要求让总数最少. 析:没什么好说的,直接用优先队列模拟就行,insert,直接放入就行了,removeMin,就得判断一下 ...
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- Codeforces Beta Round #7 B. Memory Manager 模拟题
B. Memory Manager 题目连接: http://www.codeforces.com/contest/7/problem/B Description There is little ti ...
随机推荐
- SSH 登录时出现如下错误:Disconnected:No supported authentication methods available
SSH 登录时出现如下错误:Disconnected:No supported authentication methods available 更新时间:2017-06-07 13:26:11 ...
- python 自然语言处理库https://www.nltk.org/nltk_data/
https://www.nltk.org/nltk_data/ https://github.com/hankcs/HanLP
- NCB之taxonomy系列
1.taxonomy之简介 生物分类学是研究生物系统的一种强有力的组织原则.遗传.共同遗传的同源性以及在确定功能时保护序列和结构,这些都是生物学的中心思想,直接关系到任何一组生物体的进化史.因此,分类 ...
- jQuery文档就绪事件
[jQuery文档就绪事件] 为了防止文档在完全加载(就绪)之前运行 jQuery 代码.如果在文档没有完全加载之前就运行函数,操作可能失败. $(document).ready(function() ...
- C#实现将字符串作为表达式运算
转载:http://blog.csdn.net/lifeforcode/article/details/2010807 曾经有个需求,要把一段字符串作为C#的一段语句来执行.说实在了,就类似实现计算器 ...
- metasploit framework(五):meterpreter基本命令和python扩展
基于内存的DLL注入式payload 注入合法的系统进程并建立stager 基于stager上传和预加载DLL进行扩展模块的注入(客户端API) 基于stager建立的socket连接建立加密的TLS ...
- 一些网站的meta标签的作用
转载:https://www.cnblogs.com/Lily-nercel/p/6693293.html <!DOCTYPE html> <html lang="en&q ...
- oracle 调试数据库
转载:https://www.cnblogs.com/liuqiyun/p/6589814.html 工具/原料 PL\SQL Oracle 方法/步骤 首先在PL/SQL的左侧资源栏中展 ...
- idea使用maven打包jar包
1.在pom.xml中加入以下内容: <?xml version="1.0" encoding="UTF-8"?> <project xmln ...
- jenkins权限控制
一.插件安装 插件:Role-based Authorization Strategy版本:2.3.2 二.全局安全配置 进入Jenkins后点击系统管理进入全局安全配置 当插件安装好的时候,授权策略 ...