PAT1014 Waiting in Line (30)

1014 대기 라인 (30 분) (30 분) Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the customers to wait in line are: The space inside the yellow line in front of each window is enough to contain a line with M customers. Hence when all the N lines are full, all the customers after (and including) the (NM+1)st one will have to wait in a line behind the yellow line. Each customer will choose the shortest line to wait in when crossing the yellow line. If there are two or more lines with the same length, the customer will always choose the window with the smallest number. Customer[i] will take T[i] minutes to have his/her transaction processed. The first N customers are assumed to be served at 8:00am. Now given the processing time of each customer, you are supposed to tell the exact time at which a customer has his/her business done. For example, suppose that a bank has 2 windows and each window may have 2 customers waiting inside the yellow line. There are 5 customers waiting with transactions taking 1, 2, 6, 4 and 3 minutes, respectively. At 08:00 in the morning, customer~1~ is served at window~1~ while customer~2~ is served at window~2~. Customer~3~ will wait in front of window~1~ and customer~4
순수 시 뮬 레이 션 코드 1 자신 이 쓴 h 시 뮬 레이 션 코드 2 개 를 썼 습 니 다.17: 00 은 갱 점 입 니 다. 출근 하기 전에 받 은 솥 은 아무리 늦어도 끝내 야 합 니 다.
코드 1
#include 
using namespace std;
#define MAXN 0x3f3f3f3f
int custom[10200];
int custom1[10200];
int query[10200];
int N,M,K,Q;
vector<int> window[30];
int finish[10200];
int allsize;
void add(int x,int index){
    if(x-custom1[index]>=540){
        printf("Sorry
"
); } else{ printf("%02d:%02d
"
,8+x/60,x%60); } } int findMin(){ int m=MAXN; for(int i=1;i<=N;i++){ if(window[i].size()&&custom[window[i][0]]window[i][0]]; } } return m; } int findWindow(){ int m=MAXN; int emm=0; for(int i=1;i<=N;i++){ int k=window[i].size(); if(kreturn emm; } int main(){ cin>>N>>M>>K>>Q; for(int i=1;i<=K;i++){ cin>>custom[i]; custom1[i]=custom[i];// } allsize=K;// for(int i=1;i<=K;i++){ // window[(i-1)%N+1].push_back(i); } int now=0;// while(1){ int m=findMin();// now+=m;// for(int i=1;i<=N;i++){ if(window[i].size()==0) continue; custom[window[i][0]]-=m;// -m if(!custom[window[i][0]]){ // 0 finish[window[i][0]]=now;// window[i].erase(window[i].begin());// allsize--;// -- } } int insert=findWindow();// if(allsize==0){ // int s; for(int i=1;i<=Q;i++){ cin>>s; add(finish[s],s); } return 0; } else{ for(int j=1;j<=N;j++){ // int q=window[j].size(); if(q>M){ int ans=window[j][M]; if(j!=insert){ // window[j].erase(window[j].begin()+M); window[insert].push_back(ans); } break; } } } } return 0; }

코드 2
#include 
using namespace std;
#define INF 0x3f3f3f3f
struct Customer{
    int process;
    int leave;
};
int main(){
    int N,M,K,Q;
    cin>>N>>M>>K>>Q;
    vector cus(K);
    for(int i=0;icin>>cus[i].process;
        cus[i].leave=INF;
    } 
    vector< queue<int> > winQueue(N);//          
    vector<int> timeBase(N,0);//        
    int p; 
    //           
    for(p=0;p//     ,    
    for(p;pint tmp=INF;
        int win=-1;
        for(int i=0;iint top=winQueue[i].front();//             
            if(tmp>cus[top].leave){
    //             ,            
                win=i;
                tmp=cus[top].leave;
            }
        }
        cus[p].leave=timeBase[win]+cus[p].process;
        timeBase[win]=cus[p].leave;
        winQueue[win].pop();
        winQueue[win].push(p);
    } 
    for(int i=0;iint q;
        cin>>q;
        q--;
        if(cus[q].leave-cus[q].process>=540){
    //           
            cout<<"Sorry"<else{
            printf("%02d:%02d
"
,8+cus[q].leave/60,cus[q].leave%60); } } return 0; }

좋은 웹페이지 즐겨찾기