zoukankan      html  css  js  c++  java
  • 【PAT Advanced Level】1014. Waiting in Line (30)

    简单模拟题,注意读懂题意就行

    #include <iostream>
    #include <queue>
    using namespace std;
    
    #define CUSTOMER_MAX 1000+1
    #define INF 0x6fffffff  
    
    #ifndef LOCAL
    //	#define LOCAL
    #endif LOCAL
    
    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];
    queue<int >Wait[20];
    int currTime = 0;
    int LeaveTime[CUSTOMER_MAX];
    int Timebase[20] = {0};
    
    int main()
    {
    #ifdef LOCAL
    	freopen("input.txt","r",stdin);
    	freopen("output.txt","w",stdout);
    #endif
    	cin>>n>>m>>k>>q;
    	for(int i=0;i<k;i++)
    	{
    		cin>>ProcessTime[i];
    	}
    	int index;
    	int top = 0;
    	for(int i = 0;i<2*k;i++) 
    	{
    		int min_len  = m;
    		if(top !=k) // if there are any customer not in line
    		{
    			for(int j=0;j<n;j++) 
    			{
    				if(min_len > que[j].size() )
    				{
    					min_len = que[j].size();
    					index = j;
    				}
    			}
    		}
    		if(min_len != m) // find minimum queue 
    		{
    			que[index].push(top);
    			Wait[index].push(ProcessTime[top]);
    			top++;
    		}else  // no queue available or no customer not in line, then customer pop 
    		{
    			long min_wait = INF;
    			bool empty = true;
    			for(int j=0;j<n;j++)
    			{
    				if(Wait[j].empty()) continue;
    				if(min_wait > Timebase[j]+Wait[j].front())  // find current minimum wait time
    				{
    					min_wait = Timebase[j]+Wait[j].front();
    					index = j;
    					empty = false;
    				}
    			}
    			if(empty) break;
    			Timebase[index] += Wait[index].front();
    			LeaveTime[que[index].front()] = Timebase[index];
    			que[index].pop();
    			Wait[index].pop();
    		}
    	}
    
    	//60*9	
    	int qq;
    	for(int i=0;i<q;i++)
    	{
    		cin>>qq;
    		qq--;
    		if(LeaveTime[qq]-ProcessTime[qq]<60*9)
    		{			
    			int hour = LeaveTime[qq]/60;
    			int second = LeaveTime[qq]%60;
    			printf("%02d:%02d
    ",8+hour,second);  
    		}
    		else
    			printf("Sorry
    ");
    	}
    
    #ifdef  LOCAL
    	system("PASUE");
    #endif LOCAL
    
    	return 0;
    }
    


  • 相关阅读:
    Mina、Netty、Twisted一起学(八):HTTP服务器
    Mina、Netty、Twisted一起学(七):发布/订阅(Publish/Subscribe)
    梦想还是要有的,万一实现了呢(校招季)
    我的地盘听我的
    React源码剖析系列 - 生命周期的管理艺术
    实现搜索联想
    为你的简历加分
    twobin博客样式—“蓝白之风”
    一起学习jQuery2.0.3源码—1.开篇
    this的安身之处
  • 原文地址:https://www.cnblogs.com/riskyer/p/3400384.html
Copyright © 2011-2022 走看看