大體題意:
告訴你工作站的工作起始時間 終止時間, 和處理一個人的時間間隔。
并告訴你n 個人來的時間。 求你要求的話 什么時候去 排隊時間最少, 如果你和某個人去的時間一樣,你會排在它們后面。
思路:
暴力貪心就好了。
先找有縫的,發現一個人的就診時間大于上一個人結束時間,那么直接輸出 上一個人輸出時間。
以上找的是不用排隊的時間。
如果找不到,就要找需要排隊的時間。
直接枚舉每個人來的時間,看看在這個人前面行不行,更新最小排隊時間即可。
#include <bits/stdc++.h>#define mr make_pair#define ps push_back#define fi first#define se second#define Siz(x) (int)x.size()using namespace std;typedef long long LL;typedef unsigned long long ULL;const double eps = 1e-10;const int inf = 0x3f3f3f3f;const double pi = acos(-1.0);const int maxn = 100000 + 10;int n;LL s,t,k,st[maxn],ed[maxn];LL a[maxn];int main(){ scanf("%lld %lld %lld",&s, &t, &k); scanf("%d",&n); if (n == 0) return 0 * PRintf("%lld/n",s); ///= = 好坑啊,n 能等于0 for (int i = 0; i < n; ++i){ scanf("%lld",a+i); ///每個人來的時間 } if (a[0] > s){ return 0 * printf("%lld/n",s); } memset(st,inf,sizeof st); memset(ed,inf,sizeof ed); LL la = -1; LL ans = -1; la = s+k; st[0] = s; ///每個人的開始就診時間 ed[0] = s+k;/// 每個人結束就診時間。 for (int i = 1; i < n; ++i){// printf("la = %lld",la); if (la >= t) break; if (a[i] > la){ if (la+k<=t) return 0 * printf("%lld/n",la); la = a[i]+k; st[i] = a[i]; ed[i] = a[i]+k; continue; } if (la+k > t)break; st[i] = la; ed[i] = la+k; la += k; } if (la < t && la+k<=t) return 0 * printf("%lld/n",la);///=====================///以下找需要排隊的時間 ans = 1e18; LL pos = 0; for (int i = 0; i < n; ++i){ if (st[i] == inf || ed[i] == inf)break; if (i == 0){ if (a[0] - 1 >= 0){ if (ans > st[0] - (a[0]-1) ){ ans = st[0] - (a[0]-1); pos = a[0] - 1; } } } else { if (ans > st[i] - (a[i]-1)){ ans = st[i] - (a[i] - 1); pos = a[i]-1; } } } printf("%lld/n",pos); return 0;}/**7 14 321 230 60 3101 5 6 10 12 13 18 23 24 25**/B. The Queuetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFinally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow.
He knows that the receptionist starts working after ts minutes have passed after midnight and closes after tf minutes have passed after midnight (so that (tf?-?1) is the last minute when the receptionist is still working). The receptionist spends exactly t minutes on each person in the queue. If the receptionist would stop working within t minutes, he stops serving visitors (other than the one he already serves).
Vasya also knows that exactly n visitors would come tomorrow. For each visitor Vasya knows the point of time when he would come to the passport office. Each visitor queues up and doesn't leave until he was served. If the receptionist is free when a visitor comes (in particular, if the previous visitor was just served and the queue is empty), the receptionist begins to serve the newcomer immediately.
"Reception 1"For each visitor, the point of time when he would come to the passport office is positive. Vasya can come to the office at the time zero (that is, at midnight) if he needs so, but he can come to the office only at integer points of time. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and stand in the queue after the last of them.
Vasya wants to come at such point of time that he will be served by the receptionist, and he would spend the minimum possible time in the queue. Help him!
InputThe first line contains three integers: the point of time when the receptionist begins to work ts, the point of time when the receptionist stops working tf and the time the receptionist spends on each visitor t. The second line contains one integer n — the amount of visitors (0?≤?n?≤?100?000). The third line contains positive integers in non-decreasing order — the points of time when the visitors arrive to the passport office.
All times are set in minutes and do not exceed 1012; it is guaranteed that ts?<?tf. It is also guaranteed that Vasya can arrive at the passport office at such a point of time that he would be served by the receptionist.
OutputPrint single non-negative integer — the point of time when Vasya should arrive at the passport office. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and queues up the last. If there are many answers, you can print any of them.
Examplesinput10 15 2210 13output12input8 17 343 4 5 8output2NoteIn the first example the first visitor comes exactly at the point of time when the receptionist begins to work, and he is served for two minutes. At 12 minutes after the midnight the receptionist stops serving the first visitor, and if Vasya arrives at this moment, he will be served immediately, because the next visitor would only come at 13 minutes after midnight.
In the second example, Vasya has to come before anyone else to be served.
新聞熱點
疑難解答