-
Notifications
You must be signed in to change notification settings - Fork 814
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update 1017. Queueing at Bank (25) .cpp
- Loading branch information
Showing
1 changed file
with
24 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,36 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <queue> | ||
#include <algorithm> | ||
using namespace std; | ||
struct node { | ||
const int maxn = 10005; | ||
struct person { | ||
int come, time; | ||
} tempcustomer; | ||
bool cmp1(node a, node b) { | ||
return a.come < b.come; | ||
} | ||
} p[maxn]; | ||
int cmp(person p1, person p2) { return p1.come < p2.come; } | ||
int n, k, cnt, total; | ||
int main() { | ||
int n, k; | ||
scanf("%d%d", &n, &k); | ||
vector<node> custom; | ||
for(int i = 0; i < n; i++) { | ||
int hh, mm, ss, time; | ||
scanf("%d:%d:%d %d", &hh, &mm, &ss, &time); | ||
int cometime = hh * 3600 + mm * 60 + ss; | ||
if(cometime > 61200) continue; | ||
tempcustomer = {cometime, time * 60}; | ||
custom.push_back(tempcustomer); | ||
for (int i = 1; i <= n; i++) { | ||
int hh, ss, mm, tt; | ||
scanf("%d:%d:%d %d", &hh, &mm, &ss, &tt); | ||
int sum = hh * 3600 + mm * 60 + ss; | ||
if (sum > 61200) continue; | ||
p[++cnt].time = tt * 60; | ||
p[cnt].come = sum; | ||
} | ||
sort(custom.begin(), custom.end(), cmp1); | ||
vector<int> window(k, 28800); | ||
double result = 0.0; | ||
for(int i = 0; i < custom.size(); i++) { | ||
int tempindex = 0, minfinish = window[0]; | ||
for(int j = 1; j < k; j++) { | ||
if(minfinish > window[j]) { | ||
minfinish = window[j]; | ||
tempindex = j; | ||
} | ||
} | ||
if(window[tempindex] <= custom[i].come) { | ||
window[tempindex] = custom[i].come + custom[i].time; | ||
sort(p + 1, p + 1 + cnt, cmp); | ||
priority_queue<int, vector<int>, greater<int> > q; | ||
for (int i = 1; i <= k; ++i) q.push(28800); | ||
for (int i = 1; i <= cnt; ++i) { | ||
if (q.top() <= p[i].come) { | ||
q.push(p[i].come + p[i].time); | ||
q.pop(); | ||
} else { | ||
result += (window[tempindex] - custom[i].come); | ||
window[tempindex] += custom[i].time; | ||
total += q.top() - p[i].come; | ||
q.push(q.top() + p[i].time); | ||
q.pop(); | ||
} | ||
} | ||
if(custom.size() == 0) | ||
printf("0.0"); | ||
else | ||
printf("%.1f", result / 60.0 / custom.size()); | ||
(!cnt) ? printf("0.0\n") : printf("%.1lf", ((double)total/60.0)/(double) cnt); | ||
return 0; | ||
} |