【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 ...
随机推荐
- 洛谷 P4178 Tree —— 点分治
题目:https://www.luogu.org/problemnew/show/P4178 这道题要把 dep( dis? ) 加入一个 tmp 数组里,排序,计算点对,复杂度很美: 没有写 sor ...
- la3713
2-sat...求解2-sat方案直接每个变量枚举就行了,lrj的代码很靠谱... #include<bits/stdc++.h> using namespace std; ; struc ...
- codeforces round #416 div2
A:暴力模拟 #include<bits/stdc++.h> using namespace std; int a, b; int main() { scanf("%d%d&qu ...
- [Swift通天遁地]九、拔剑吧-(2)在项目中使用大量美观的图标
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 能力 or say 职业 规划
2019.5.8 黑盒测试,白盒测试,接口测试,自动化测试,性能测试.. 往测试工程师发展,再是测试开发,高级测试开发.. 要是真的喜欢前端,可以再转吧.前端后端应该要清楚它们的区别 前端:广度, ...
- POJ 1873 计算几何
思路: 二进制枚举一下要删哪些点 求个凸包,算一下贡献 //By SiriusRen #include <cmath> #include <cstdio> #include & ...
- 10 在C#中读取文件
我们在前一个练习中已经了解了如何在C#控制台程序(console)中读取用户的输入.现在我们要学习如何从一个文件中读取内容.在下面的练习中,你要格外小心.关于文件的操作,一不小心会损失你的重要文件. ...
- 01--SQLite学习网站参考
1. SQLite基本操作 见我的02—SQLite一步到位 sqlite3编程笔记 . http://blog.csdn.net/wl_haanel/article/details/623141 ...
- Linux 一些小知识点汇总(持续更新....)
一.符号 1.$@:传递的参数. 2.$# :传递参数的数量. 3.$?:指上一次执行命令后的返回值.一般0表示运行成功. 补充:$?只表示上一个命令执行后的退出状态,当命令执行后,又执行了其他命令, ...
- java_遍历文件目录
package util; import java.io.File; import java.io.IOException; //列出File的一些常用操作 public class util { / ...