【题目链接】:
【题意】
排队去办护照; 给你n个人何时来的信息; 然后问你应该何时去才能在队伍中等待的时间最短; (如果你和别人同时到,你要等到和你同时到的人全都办完了才轮到你);【题解】
细节题吧。 首先大体思路就是; 枚举那个人在哪个人办完之后办; 如果那个人办完之后和下一个时间的人之间有空隙->直接输出那个枚举的人办完后的时间->因为这表示等待时间为0的情况; 否则如果没有空隙,那么就要在下一个时间的人之前一个单位的时间来; 这样等待的时间尽量最短; 然后取最小值就好; 当然还有一种就是在第一个人之前半,或者没有一个人直接在ts时刻来就好; 这两类取较小值就好; 坑点: 题目没讲清楚的就是 如果在时间点20,服务一个人要10分钟,然后tf=30,那么如果这个时刻来人 那个人是可以被服务的。 初始时间要分t[1]< ts和t[1]>=ts两类赋值; 【完整代码】#includeusing 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