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 ...
随机推荐
- ZooKeeper分层次的法定人数(十二)
分层次的法定人数的介绍 这个文档给出一个关于怎么使用分层次的法定人数的例子.基本思路是很简单的.首先,我们把服务端分组,然后每一组一行.下一步我们分配一个权重为每一个服务端. 下面的例子展示了怎么每组 ...
- ZJOI2002 昂贵的聘礼
题目描述 Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿不出这么多金币,便请 ...
- vector基础
//STL基础 //容器 //vector #include "iostream" #include "cstdio" #include "vecto ...
- linux内存相关好文(转)
话说团队的兄弟有一天问我,为啥咱唯一的一个服务器,内存都用完了,我还想在上面测性能呢.我一听,第一反应:不可能!我说你胡扯呢吧,咱那可是16G的一个物理机,上面就跑了git服务器,怎么可能把内存吃完了 ...
- photoshop的魔棒工具怎么用来抠图
魔棒工具是photoshop中提供的一种可以快速形成选区的工具,对于颜色边界分界明显的图片,能够一键形成选区,方便快捷. 本教程通过一个简单的实例,教新手怎么用Photoshop魔棒工具快速形成抠图选 ...
- bzoj 3126: [Usaco2013 Open]Photo——单调队列优化dp
Description 给你一个n长度的数轴和m个区间,每个区间里有且仅有一个点,问能有多少个点 Input * Line 1: Two integers N and M. * Lines 2..M+ ...
- hdu 1232 畅通工程(并查集算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1232 畅通工程 Time Limit: 4000/2000 MS (Java/Others) M ...
- zuul进行rate limit
maven <dependency> <groupId>com.marcosbarbero.cloud</groupId> <artifactId>sp ...
- Vue组件-组件的属性
在html中使用元素,会有一些属性,如class,id,还可以绑定事件,自定义组件也是可以的.当在一个组件中,使用了其他自定义组件时,就会利用子组件的属性和事件来和父组件进行数据交流. 比如,子组件需 ...
- Linux内核的架构
GNU/Linux操作系统架构 备注:IPC进程间通.IPC(Inter-Process Communication)是共享"命名管道"的资源,它是为了让进程间通信而开放的命名管道 ...