【codeforces 767B】The Queue
【题目链接】:http://codeforces.com/contest/767/problem/B
【题意】
排队去办护照;
给你n个人何时来的信息;
然后问你应该何时去才能在队伍中等待的时间最短;
(如果你和别人同时到,你要等到和你同时到的人全都办完了才轮到你);
【题解】
细节题吧。
首先大体思路就是;
枚举那个人在哪个人办完之后办;
如果那个人办完之后和下一个时间的人之间有空隙->直接输出那个枚举的人办完后的时间->因为这表示等待时间为0的情况;
否则如果没有空隙,那么就要在下一个时间的人之前一个单位的时间来;
这样等待的时间尽量最短;
然后取最小值就好;
当然还有一种就是在第一个人之前半,或者没有一个人直接在ts时刻来就好;
这两类取较小值就好;
坑点:
题目没讲清楚的就是
如果在时间点20,服务一个人要10分钟,然后tf=30,那么如果这个时刻来人
那个人是可以被服务的。
初始时间要分t[1]< ts和t[1]>=ts两类赋值;
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 1e5+100;
LL ts,tf;
LL T[N],now,t,idxtt=-1,tt;
int n;
int main()
{
//freopen("D:\\rush.txt", "r", stdin);
rel(ts),rel(tf);rel(t);
rei(n);
rep1(i,1,n)
rel(T[i]);
if (T[1]<ts)
now = ts;
else
now = T[1];
rep1(i,1,n)
{
int l = i,r = i;
while (r+1<=n && T[r+1]==T[l]) r++;
int num = r-l+1;
LL extcost=0;
now+=1LL*t*num;
if (now+t>tf) break;
if (r+1<=n)
{
if (now<=T[r+1]-1)
{
printf("%lld\n",now);
return 0;
}
else
{
if (now>=T[r+1])
{
LL idx = T[r+1]-1,ttemp = 0;
ttemp += now-idx;
if (idxtt==-1)
{
idxtt = idx;
tt = ttemp;
}
else
if (tt>ttemp)
{
idxtt = idx;
tt = ttemp;
}
}
}
}
else
{
printf("%lld\n",now);
return 0;
}
i = r;
}
if (n==0 || T[1]>ts)
{
return printf("%lld\n",ts),0;
}
else
//t[1]<=ts
{
LL spt = T[1]-1;
LL wait = ts-spt;
if (idxtt==-1 || wait<tt)
idxtt = spt;
}
printf("%lld\n",idxtt);
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
【codeforces 767B】The Queue的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
- 【codeforces 510C】Fox And Names
[题目链接]:http://codeforces.com/contest/510/problem/C [题意] 给你n个字符串; 问你要怎么修改字典序; (即原本是a,b,c..z现在你可以修改每个字 ...
- 【codeforces 796D】Police Stations
[题目链接]:http://codeforces.com/contest/796/problem/D [题意] 在一棵树上,保证每个点在距离d之内都有一个警察局; 让你删掉最多的边,使得剩下的森林仍然 ...
- 【codeforces 716D】Complete The Graph
[题目链接]:http://codeforces.com/problemset/problem/716/D [题意] 给你一张图; 这张图上有一些边的权值未知; 让你确定这些权值(改成一个正整数) 使 ...
- 【codeforces 505D】Mr. Kitayuta's Technology
[题目链接]:http://codeforces.com/problemset/problem/505/D [题意] 让你构造一张有向图; n个点; 以及所要求的m对联通关系(xi,yi) 即要求这张 ...
- 【codeforces 95C】Volleyball
[题目链接]:http://codeforces.com/problemset/problem/95/C [题意] 给你n个点,m条边; 每个点有一辆出租车; 可以到达离这个点距离不超过u的点,且在这 ...
- 【19.77%】【codeforces 570D】Tree Requests
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【34.57%】【codeforces 557D】Vitaly and Cycle
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- 关于OpenFileDialog的使用(转)
OpenFileDialog控件有以下基本属性 InitialDirectory 对话框的初始目录 Filter 要在对话框中显示的文件筛选器,例如,"文本文件(*.txt)|*.txt|所 ...
- vue动态绑定class的最常用几种方式
vue动态绑定class的最常用几种方式: 第一种:(最简单的绑定) 1.绑定单个class html部分: <div :class="{'active':isActive}&quo ...
- Counterfeit Dollar
http://poj.org/problem?id=1013 #include<stdio.h> #include<string.h> #include<math.h&g ...
- linux修改yum源
在自己安装的CentOS6.5中使用yum安装软件,总是提示404错误信息,百度后发现原来要设置yum源. 在安装完CentOS后一般需要修改yum源,才能够在安装更新rpm包时获得比较理想的速度.国 ...
- 洛谷P1182数列分段
题目描述 对于给定的一个长度为N的正整数数列A[i],现要将其分成M(M≤N)段,并要求每段连续,且每段和的最大值最小. 关于最大值最小: 例如一数列4 2 4 5 1要分成3段 将其如下分段: [4 ...
- codevs1040统计单词个数(区间+划分型dp)
1040 统计单词个数 2001年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 给出一个长度不超 ...
- Python细节(一)深浅拷贝
深浅拷贝 只要涉及拷贝,就会涉及创建新对象 浅拷贝,会创建一个新的容器,列表中的元素和原列表的元素用的是同一个内存空间 第一种方法:从头切到尾,完整的复制一份 lst = [1,2,3,4] lst1 ...
- Golang 入门 : goroutine(协程)
在操作系统中,执行体是个抽象的概念.与之对应的实体有进程.线程以及协程(coroutine).协程也叫轻量级的线程,与传统的进程和线程相比,协程的最大特点是 "轻"!可以轻松创建上 ...
- sql case when 用法
sql语言中有没有类似C语言中的switch case的语句?? 没有,用case when 来代替就行了. 例如,下面的语句显示中文年月 select ...
- An problem about date 根据年月日计算 星期几
/W = (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7(1.2月需要看作上一年的13.14月) #include<stdio.h> #include& ...