【Codeforces Round #398 (Div. 2)】Codeforces 767B The Queue

2023-11-07 20:09
文章标签 codeforces round div queue 398 767b

本文主要是介绍【Codeforces Round #398 (Div. 2)】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! Input
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. Output 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.

肯定要在某个人前一秒到达,到的更早没有意义,到的更晚就被他抢先了。
这样可以 O(n) 枚举一遍解决。
但是要考虑各种情况,比如在所有人之后到、别人到的时间都不在规定时间内。

#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
const LL oo=1e15;
LL a[100010],ts,tf,t;
int n;
int main()
{LL now,ans,ansv=oo;scanf("%I64d%I64d%I64d%d",&ts,&tf,&t,&n);for (int i=1;i<=n;i++) scanf("%I64d",&a[i]);now=ts;if (a[1]>ts){printf("%d\n",ts);return 0;} for (int i=1;i<=n;i++){if (max(0LL,now-a[i]+1)<ansv&&a[i]-1+t<=tf){ansv=max(0LL,now-a[i]+1);ans=a[i]-1;}now=max(now,a[i])+t;}if (now+t<=tf) printf("%I64d\n",now);else printf("%I64d\n",ans);
}

这篇关于【Codeforces Round #398 (Div. 2)】Codeforces 767B The Queue的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/365992

相关文章

Codeforces Round #240 (Div. 2) E分治算法探究1

Codeforces Round #240 (Div. 2) E  http://codeforces.com/contest/415/problem/E 2^n个数,每次操作将其分成2^q份,对于每一份内部的数进行翻转(逆序),每次操作完后输出操作后新序列的逆序对数。 图一:  划分子问题。 图二: 分而治之,=>  合并 。 图三: 回溯:

C++——stack、queue的实现及deque的介绍

目录 1.stack与queue的实现 1.1stack的实现  1.2 queue的实现 2.重温vector、list、stack、queue的介绍 2.1 STL标准库中stack和queue的底层结构  3.deque的简单介绍 3.1为什么选择deque作为stack和queue的底层默认容器  3.2 STL中对stack与queue的模拟实现 ①stack模拟实现

Codeforces Round #261 (Div. 2)小记

A  XX注意最后输出满足条件,我也不知道为什么写的这么长。 #define X first#define Y secondvector<pair<int , int> > a ;int can(pair<int , int> c){return -1000 <= c.X && c.X <= 1000&& -1000 <= c.Y && c.Y <= 1000 ;}int m

Codeforces Beta Round #47 C凸包 (最终写法)

题意慢慢看。 typedef long long LL ;int cmp(double x){if(fabs(x) < 1e-8) return 0 ;return x > 0 ? 1 : -1 ;}struct point{double x , y ;point(){}point(double _x , double _y):x(_x) , y(_y){}point op

Codeforces Round #113 (Div. 2) B 判断多边形是否在凸包内

题目点击打开链接 凸多边形A, 多边形B, 判断B是否严格在A内。  注意AB有重点 。  将A,B上的点合在一起求凸包,如果凸包上的点是B的某个点,则B肯定不在A内。 或者说B上的某点在凸包的边上则也说明B不严格在A里面。 这个处理有个巧妙的方法,只需在求凸包的时候, <=  改成< 也就是说凸包一条边上的所有点都重复点都记录在凸包里面了。 另外不能去重点。 int

Codeforces 482B 线段树

求是否存在这样的n个数; m次操作,每次操作就是三个数 l ,r,val          a[l] & a[l+1] &......&a[r] = val 就是区间l---r上的与的值为val 。 也就是意味着区间[L , R] 每个数要执行 | val 操作  最后判断  a[l] & a[l+1] &......&a[r] 是否= val import ja

ActiveMQ—Queue与Topic区别

Queue与Topic区别 转自:http://blog.csdn.net/qq_21033663/article/details/52458305 队列(Queue)和主题(Topic)是JMS支持的两种消息传递模型:         1、点对点(point-to-point,简称PTP)Queue消息传递模型:         通过该消息传递模型,一个应用程序(即消息生产者)可以

CSS实现DIV三角形

本文内容收集来自网络 #triangle-up {width: 0;height: 0;border-left: 50px solid transparent;border-right: 50px solid transparent;border-bottom: 100px solid red;} #triangle-down {width: 0;height: 0;bor

Java-数据结构-栈和队列-Stack和Queue (o゚▽゚)o

文本目录: ❄️一、栈(Stack):     ▶ 1、栈的概念:   ▶ 2、栈的使用和自实现:      ☑ 1)、Stack():       ☑ 2)、push(E e):      ☑ 3)、empty():         ☑ 4)、peek(E e):        ☑ 5)、pop(E e):       ☑ 6)、size(E e):  ▶ 3、栈自实现的总代

创建一个大的DIV,里面的包含两个DIV是可以自由移动

创建一个大的DIV,里面的包含两个DIV是可以自由移动 <body>         <div style="position: relative; background:#DDF8CF;line-height: 50px"> <div style="text-align: center; width: 100%;padding-top: 0px;"><h3>定&nbsp;位&nbsp;