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 ...
随机推荐
- [ASP.NET]从ASP.NET Postback机制,到POST/GET方法
写这篇博客的起源来自于自己最近在学习ASP.NET时对于 PostBack机制的困惑.因为自己在解决困惑地同时,会不断产生新的疑问,因此博客最后深入到了http 包的格式和Internet所使用的TC ...
- ZooKeeper JMX(十一)
JMX ZooKeeper对JMX有额外的支持,允许你查看和管理Zk群集. 这个文档假设你对JMX有基本的了解.参考Sun JMX Technology来对JMX进行入门. 关于安装一个本地和远端管理 ...
- 51Nod 1080
#include "bits/stdc++.h" using namespace std; #define LL long long #define INF 0x3f3f3f3f3 ...
- MyBatis注解Annotation介绍及Demo
MyBatis注解Annotation介绍及Demo 2014-04-21 17:09:55 标签:Mybatis Annotation 注解 ResultMap SqlBuilder 原创作品,允 ...
- 「6月雅礼集训 2017 Day4」寻找天哥
[题目大意] 给出$n$个三维向量,设当前向量长度为$L$,每次沿着向量等概率走$[0,L]$个长度.一个球每秒半径增加1个长度,直到覆盖位置,每秒耗能为球体积,求总耗能的期望. 设最后半径为R,那么 ...
- HDU 1002 A + B Problem II (大数加法)
题目链接 Problem Description I have a very simple problem for you. Given two integers A and B, your job ...
- HDU 4757 可持久化trie树
首先如果给定一些数,询问这些数中哪个数^给定的数的值最大的话,我们可以建立一颗trie树,根连接的两条边分别为0,1,表示二进制下第15位,那么我们可以建立一颗trie树,每一条从根到叶子节点的链表示 ...
- 特征工程(Feature Engineering)
一.什么是特征工程? "Feature engineering is the process of transforming raw data into features that bett ...
- AGC025简要题解
AGC025简要题解 B RGB Coloring 一道简单题,枚举即可. C Interval Game 考虑可以进行的操作只有两种,即左拉和右拉,连续进行两次相同的操作是没有用的. 左拉时肯定会选 ...
- Linux内核堆栈使用方法 进程0和进程1【转】
转自:http://blog.csdn.net/yihaolovem/article/details/37119971 目录(?)[-] 8 Linux 系统中堆栈的使用方法 81 初始化阶段 82 ...