博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【codeforces 767B】The Queue
阅读量:4313 次
发布时间:2019-06-06

本文共 2211 字,大约阅读时间需要 7 分钟。

【题目链接】:

【题意】

排队去办护照;
给你n个人何时来的信息;
然后问你应该何时去才能在队伍中等待的时间最短;
(如果你和别人同时到,你要等到和你同时到的人全都办完了才轮到你);

【题解】

细节题吧。
首先大体思路就是;
枚举那个人在哪个人办完之后办;
如果那个人办完之后和下一个时间的人之间有空隙->直接输出那个枚举的人办完后的时间->因为这表示等待时间为0的情况;
否则如果没有空隙,那么就要在下一个时间的人之前一个单位的时间来;
这样等待的时间尽量最短;
然后取最小值就好;
当然还有一种就是在第一个人之前半,或者没有一个人直接在ts时刻来就好;
这两类取较小值就好;
坑点:
题目没讲清楚的就是
如果在时间点20,服务一个人要10分钟,然后tf=30,那么如果这个时刻来人
那个人是可以被服务的。
初始时间要分t[1]< ts和t[1]>=ts两类赋值;
【完整代码】

#include 
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
pii;typedef pair
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]
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

转载于:https://www.cnblogs.com/AWCXV/p/7626502.html

你可能感兴趣的文章
docker-daemon.json各配置详解
查看>>
Docker(一)使用阿里云容器镜像服务
查看>>
Docker(三) 构建镜像
查看>>
FFmpeg 新旧版本编码 API 的区别
查看>>
RecyclerView 源码深入解析——绘制流程、缓存机制、动画等
查看>>
Android 面试题整理总结(一)Java 基础
查看>>
Android 面试题整理总结(二)Java 集合
查看>>
学习笔记_vnpy实战培训day02
查看>>
学习笔记_vnpy实战培训day03
查看>>
VNPY- VnTrader基本使用
查看>>
VNPY - CTA策略模块策略开发
查看>>
VNPY - 事件引擎
查看>>
MongoDB基本语法和操作入门
查看>>
学习笔记_vnpy实战培训day04_作业
查看>>
OCO订单(委托)
查看>>
学习笔记_vnpy实战培训day06
查看>>
回测引擎代码分析流程图
查看>>
Excel 如何制作时间轴
查看>>
matplotlib绘图跳过时间段的处理方案
查看>>
vnpy学习_04回测评价指标的缺陷
查看>>