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 ...
随机推荐
- Nginx简介及使用Nginx实现负载均衡的原理【通俗易懂,言简意赅】【转】
Nginx 这个轻量级.高性能的 web server 主要可以干两件事情: 直接作为http server(代替apache,对PHP需要FastCGI处理器支持): 另外一个功能就是作为反向代理服 ...
- frame外弹出,刷新父页面
//刷新父页面 function reflashParent() { var id = parent.tabbar.getActiveTab(); id = id.replace('tab','mai ...
- sqlserver 个人整理
1.创建临时表(临时表的生命周期是当前回话中) //创建临时表是使用#+表名 //判断临时表是否存在 if object_id('tempdb..#ttt1') is not null Begin d ...
- JAVA JDBC(存储过程和事务管理)
1.什么是存储过程 存储过程(Stored Procedure)是在大型数据库系统中,一组为了完成特定功能的SQL 语句集,存储在数据库中,经过第一次编译后再次调用不需要再次编译,用户通过指定存储过程 ...
- u3d局域网游戏网络(c# socket select 模型)——续
原文:http://www.cnblogs.com/saucerman/p/5555793.html 因为项目要加语音.语音数据都非常大.所以顺带就把之前写的网络模块一起测试了. 然后发现了一些bug ...
- 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛) F.猴子排序的期望
题目链接:https://www.nowcoder.com/acm/contest/116/F 题目描述 我们知道有一种神奇的排序方法叫做猴子排序,就是把待排序的数字写在卡片上,然后让猴子把卡片扔在空 ...
- mysql查询语句的执行顺序(重点)
一 SELECT语句关键字的定义顺序 SELECT DISTINCT <select_list> FROM <left_table> <join_type> JOI ...
- Linux 入门记录:十九、Linux 包管理工具 RPM
一.源代码管理 绝大多数开源软件都是直接以源代码形式发布的,一般会被打包为 tar.gz 的归档压缩文件.程序源代码需要编译为二进制可执行文件后才能够运行使用.源代码的基本编译流程为: ./confi ...
- charger related source code position
Platform Qualcomm MSM8917 or MSM8937 Source kernel/msm-3.18/drivers/power/qpnp-smbcharger.c kernel/m ...
- 【Android XML】Android XML 转 Java Code 系列之 Selector(2)
今天我们要把drawable下的selector的XML文件转换成Java代码.(打包进jar,不依赖apk) 在转换工具中的代码为: https://github.com/SickWorm/Andr ...