Sorry
#include <iostream> #include <queue> #include <stdio.h> using namespace std; #define CUSTOMER_MAX 1000+5 #define INF 0x6fffffff int n; // number of windows <=20 int m ;// queue capacity <=10 int k; // customers <=1000 int q; // query times <=1000 int ProcessTime[CUSTOMER_MAX]; // queue<int> que[20+5]; int LeaveTime[CUSTOMER_MAX]={0}; int Timebase[20+5] = {0}; int main() { cin>>n>>m>>k>>q; for(int i=0;i<k;i++) { cin>>ProcessTime[i]; } int index; int top = 0; // n*m for (int i=0;top<m*n && top<k;top++) { que[i].push(top); LeaveTime[top] = Timebase[i]+ProcessTime[top]; Timebase[i] = LeaveTime[top]; i = (i+1)%n; } for(;top<k;top++) // pop and push { // find earliest leave customer int min_wait = INF; int found = false; for(int j=0;j<n;j++) { int cus = que[j].front(); if(min_wait > LeaveTime[cus]) // can not be empty { min_wait = LeaveTime[cus]; index = j; found = true; } } que[index].pop(); que[index].push(top); LeaveTime[top] = Timebase[index] + ProcessTime[top]; Timebase[index] = LeaveTime[top]; } while(q--) { int qq; cin>>qq; qq--; if(LeaveTime[qq]-ProcessTime[qq]>=60*9) { printf("Sorry\n"); } else { int hour = LeaveTime[qq]/60; int second = LeaveTime[qq]%60; printf("%02d:%02d\n",8+hour,second); } } return 0; }
原文地址:http://blog.csdn.net/jason_wang1989/article/details/43939851