【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 ...
随机推荐
- ASP.NET SignalR Hubs API Guide - JavaScript Client
https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-javascript- ...
- js【面向过程编程】、好、 【init()、 GetData()、 bindData()、bindDom、 bindEvent()、buyProduct()、AddProductToCart()】*****************
1. 一般页面开发方式 [可读性差.可维护性差]------初级开发工程师 一般页面编写方法 var name = 'iphone8' var description = '手机中的战斗机 ' var ...
- balsamiq mockups 注册
Name: helloWorld Key: eJzzzU/OLi0odswsqslIzcnJD88vykmpsUQCNc41hjV+7q5+AF74Ds8=
- [Django基础] gunicorn启动django时静态文件的加载
目前在用nginx+gunicorn对django进行部署 当我用gunicorn -w 4 -b 127.0.0.1:8080 myproject.wsig:application启动django时 ...
- bzoj2744 [HEOI2012]朋友圈——二分图匹配
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2744 首先,求一个图的最大团等价于求它的补图的最大独立集,而二分图的最大独立集 = 总点数 ...
- 收集主机OS相关数据
#!/usr/bin/ksh touch hostinfo$(date +%Y%m%d).csv filename=hostinfo$(date +%Y%m%d).csv >${filename ...
- Request returned failure status 401
Request returned failure status 401.Invalid OpenStack Identity credentials.
- 0606-工厂模式、单例模式、DBDA的单例和完整功能
工厂模式:只要指定类名,就可以据此获取一个该类的对象. 单例模式:某个类,只允许其“创建”出一个对象. 单例的方法:三私一公(一个私有化对象,一个私有化构造方法,一个私有化克隆方法,一个公共方法返回对 ...
- [Swift通天遁地]三、手势与图表-(9)制作五彩缤纷的气泡图表
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 元组Tuple、数组Array、映射Map
一.元组Tuple 元组Tuple是不同类型的值的聚集,元组的值将单个的值包含在圆括号中来构成,元组可以包含一个不同类型的元素 如 val riple = (100, "Scala" ...