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 ...
随机推荐
- 怎么修改jar包中的class文件然后再重新打成jar包
1.导入到eclipse中, 修改完了 然后导出jar即可 2.jar cf file.jar *.class 将当前目录下所有CLASS文件打包成新的JAR文件 3.对于补丁.之前已经有jar 例如 ...
- mysql 在查询结果中进行二次查询
第一次查询:查询身份证编号和出现次数 select cardid,count(cardid) as total from p_person_info group by cardid 在第一次查询结果进 ...
- Mantis 从Windows 迁移到Linux上
1. 导出windows manits的mysql数据库文件, 在cmd运行:mysqldump -uroot -p3edc$RFV bugtracker > C:/mantis.sql; 2. ...
- 【BZOJ4837】LRU算法 [模拟]
LRU算法 Time Limit: 6 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 小Q同学在学习操作系统中内存管理的 ...
- 使用TSQL语句操作MySQL数据库
使用TSQL语句创建数据库 以前用的是鼠标在界面上手动创建,这样创建会比较麻烦,而且还会经常出问题.在其它电脑上要用的话还需要重复操作.所以要使用程序代码操作,能通过代码的就不用手动操作. 在数据库界 ...
- POJ 3069 Saruman's Army (模拟)
题目连接 Description Saruman the White must lead his army along a straight path from Isengard to Helm's ...
- HDU 1312 Red and Black (深搜)
题目链接 Problem Description There is a rectangular room, covered with square tiles. Each tile is colore ...
- oracle scott用户不存在
scott用户拥有一些基础的数据表,可以供我们练习sql.先执行 alter user scott account unlock; 查看scott用户是否存在 当scott用户不存在,我们就需要在$O ...
- Low overhead memory space management
Methods, apparatus, and systems, including computer programs encoded on a computer storage medium, m ...
- 【模板】BZOJ 3781: 小B的询问 莫队算法
http://www.lydsy.com/JudgeOnline/problem.php?id=3781 N个数的序列,每次询问区间中每种数字出现次数的平方和,可以离线. 丢模板: #include ...