CodeForces 767B The Queue
模拟。
情况有点多,需要仔细。另外感觉题目的$tf$有点不太对......而且数据水了。
$0$ $5$ $2$
$2$
$0$ $5$
这组数据按照题意的话答案可以是$2$和$4$,但是好多错的答案能$AC$。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c))
{
x = x * + c - '';
c = getchar();
}
} LL INF=0x7FFFFFFF;
LL ts,tf,t;
int n;
LL s[]; int main()
{
INF=INF*INF; INF=INF*; scanf("%lld%lld%lld",&ts,&tf,&t);
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%lld",&s[i]); if(n==)
{
printf("%lld\n",ts);
return ;
} if(s[]>ts)
{
printf("%lld\n",ts);
return ;
} LL need=INF,idx=-,last=ts,tmp; last=max(last,s[])+t;
for(int i=;i<=n;i++)
{
if(s[i]==s[i-])
{
last=max(last,s[i])+t;
continue;
}
if(s[i-]<=tf)
{
tmp=last+t;
if(tmp<=tf&&tmp-s[i-]<need) idx=s[i-],need=tmp-s[i-];
}
if(s[i]-<=tf)
{
tmp=max(s[i]-,last)+t;
if(tmp<=tf&&tmp-(s[i]-)<need) idx=s[i]-,need=tmp-(s[i]-);
}
if(last>=s[i-]&&last<s[i])
{
tmp=last+t;
if(tmp<=tf&&tmp-last<need) idx=last,need=tmp-last;
} last=max(last,s[i])+t;
} if(s[]!=)
{
tmp=ts+t;
if(<=tf)
{
if(tmp<=tf&&tmp-<need) idx=,need=tmp-;
}
tmp=max(s[]-,ts)+t;
if(s[]-<=tf)
{
if(tmp<=tf&&tmp-(s[]-)<need) idx=s[]-,need=tmp-(s[]-);
}
} tmp=last+t;
if(s[n]<=tf)
{
if(tmp<=tf&&tmp-s[n]<need) idx=s[n],need=tmp-s[n];
}
if(last<=tf)
{
if(tmp<=tf&&tmp-last<need) idx=last,need=tmp-last;
} printf("%lld\n",idx); return ;
}
CodeForces 767B The Queue的更多相关文章
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces 28C Bath Queue 【计数类DP】*
Codeforces 28C Bath Queue LINK 简要题意:有 n 个人等概率随机进入 m 个房间,一个房间可以有多个人,第 i 个房间有 ai 个水龙头,在一个房间的人要去排队装水,他们 ...
- 【codeforces 767B】The Queue
[题目链接]:http://codeforces.com/contest/767/problem/B [题意] 排队去办护照; 给你n个人何时来的信息; 然后问你应该何时去才能在队伍中等待的时间最短; ...
- Codeforces 435 A Queue on Bus Stop
题意:给出n队人坐车,车每次只能装载m人,并且同一队的人必须坐同一辆车,问最少需要多少辆车 自己写的时候想的是从前往后扫,看多少队的人的和小于m为同一辆车,再接着扫 不过写出来不对 后来发现把每一队的 ...
- 【Codeforces 91B】Queue
[链接] 我是链接,点我呀:) [题意] [题解] 对于每个i,用二分的方法求出来y所在的位置j. 可以这样求. 假设现在二分到了位置mid. 那么随便用个rmq求出来mid..n这一段的最小值tem ...
- Codeforces 85B. Embassy Queue【段树、馋】
标题效果: 每个人都应该申请签证必须向大使馆3种程序,而这3个步骤做的顺序是固定的.通过各种形式的手续给出多少,它需要对每个过程的处理时间,有多少人会来办理手续,什么时间来.要求的是全部人分别在大使馆 ...
- CodeForces - 28C Bath Queue 概率与期望
我概率期望真是垃圾--,这题搞了两个钟头-- 题意 有\(n\)个人,\(m\)个浴室,每个浴室里有\(a_i\)个浴缸.每个人会等概率随机选择一个浴室,然后每个浴室中尽量平分到每个浴缸.问期望最长排 ...
- Codeforces Educational Round 37
Solved CodeForces 920A Water The Garden Solved CodeForces 920B Tea Queue Solved CodeForces ...
- codeforces D. Queue 找规律+递推
题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...
随机推荐
- eclipse如何远程debug/断开远程debug
eclipse如何远程debug? 当你的代码已经部署到生产或者测试环境的时候,你如何debug判断线上的问题呢? debug之前必须保证本地代码和远程代码完全一致,否则将不能建立连接 在eclips ...
- redhat 7 配置yum本地源
http://www.unixarena.com/2015/04/how-to-create-the-yum-repository-on-rhel-7.html 1. 在虚拟机上挂上cd 2. m ...
- Spring 与 Quartz 动态配置(数漫江湖)
因为项目的需求,需要有动态配置计划任务的功能.本文在 Quartz JobBean 中获取配置的 Quartz cronExpression 时间表达式及 Spring Bean 的对象名.方法名并运 ...
- 边绘边理解prototype跟__proto__
网上流传着一张讲解prototype跟__proto__关系的图,尽管他已经描绘的很清楚了,但对于初学者来说,江太公感觉还是过于纠结,于是起心重绘,让他们之间的关系更加明晰可理解,一方面出于分享目的, ...
- Java的Integer常量池和String常量池
1.Integer的常量池 看下面一段代码: package cn.qlq.test; public class ArrayTest { public static void main(String[ ...
- perl中设置POST登录时的重定向
默认地, perl提交post登录时是不会重定向的 要让它重定向, 可以用如下方法: my $cookie = HTTP::Cookies->new(); push @{$ua->requ ...
- linux编程之消息队列
消息队列是内核地址空间中的内部链表,通过linux内核在各个进程之间传递内容,消息顺序地发送到消息队列中,并且以几种不同的方式 从队列中获取,每个消息队列可以用IPC标识符唯一的进行标识,内核中的消息 ...
- Python基础=== Tkinter Grid布局管理器详解
本文转自:https://www.cnblogs.com/ruo-li-suo-yi/p/7425307.html @ 箬笠蓑衣 Grid(网格)布局管理器会将控件放置到一个二维的表 ...
- .net爬虫了解一下
using System; //添加selenium的引用 using OpenQA.Selenium.PhantomJS; using OpenQA.Selenium.Chrome; using O ...
- 相册框架之AssetsLibrary
看到项目中用到AssetsLibrary这个框架, 所以研究了一下 其实很简单 - (void)getAlbumPhoto { NSString *tipTextWhenNoPhotosAuthori ...