1014 Waiting in Line (30 分)(数组)

匿名 (未验证) 提交于 2019-12-02 23:05:13

  • 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.

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.

Input Specification:

Output Specification:

HH:MMHHMMSorry

Sample Input:

 2 2 7 5 1 2 6 4 3 534 2 3 4 5 6 7 

Sample Output:

 08:07 08:06 08:10 17:00 Sorry
 #include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1001; int main(){ 	int n,m,k,q; 	int time[maxn],ans[maxn],wait[maxn],pro[21][11]; 	memset(pro,0,sizeof(pro)); 	memset(time,0,sizeof(time)); 	cin>>n>>m>>k>>q; 	for(int i=1;i<=k;i++){ 		cin>>time[i]; 	} 	if(k>n){ 		int x=1,y=1; 		for(int i=1;i<=k;i++){//x表示窗口,y表示窗口前面的队伍  			if(i<=n*m){ 				if(x>n){ 					x=1; 					y+=1; 				} 				pro[x][y]=time[i]+pro[x][y-1]; 				ans[i]=pro[x][y]; 				wait[i]=pro[x][y-1]; 				x++; 			} 			else{ 				if(i==n*m+1){ 					for(int j=1;j<=n;j++){//pro[j][0]表示每个窗口第一个人  						pro[j][0]=1; 					}	 				} 				int loc,mn=0x3f3f3f3f;  				for(int j=1;j<=n;j++){ 					if(pro[j][pro[j][0]]<mn){ 						loc=j; 						mn=pro[j][pro[j][0]]; 					} 				} 				if(pro[loc][0]==1){ 					pro[loc][pro[loc][0]]=time[i]+pro[loc][m]; 					wait[i]=pro[loc][m]; 				} 				else{ 					pro[loc][pro[loc][0]]=time[i]+pro[loc][pro[loc][0]-1]; 					wait[i]=pro[loc][pro[loc][0]-1]; 				} 				ans[i]=pro[loc][pro[loc][0]]; 				pro[loc][0]++; 				if(pro[loc][0]>m){ 					pro[loc][0]=1; 				} 			} 		} 	} 	else{ 		for(int i=1;i<=k;i++){ 			ans[i]=time[i]; 		} 	} 	int ask; 	for(int i=0;i<q;i++){ 		cin>>ask; 		int hour=8,min=0; 		hour+=ans[ask]/60; 		min+=ans[ask]%60; 		if(wait[ask]<540){//被服务时间在17:00之前的才能处理,输出处理结束后的时间 			printf("%02d:%02d\n",hour,min); 		} 		else{ 			printf("Sorry\n"); 		} 	}     return 0; } 

文章来源: https://blog.csdn.net/qq_42711300/article/details/86775367
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!