【学习笔记】〖九度OJ〗题目1326:Waiting in Line

题目1326:Waiting in Line

时间限制:1 秒

内存限制:32 兆

特殊判题:否

提交:190

解决:53

题目描述:

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 custmers 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, customer1 is served at window1 while customer2 is served at window2. Customer3 will wait in front of window1 and customer4 will wait in front of window2. Customer5 will wait behind the yellow line.

At 08:01, customer1 is done and customer5 enters the line in front of window1 since that line seems shorter now. Customer2 will leave at 08:02, customer4 at 08:06, customer3 at 08:07, and finally customer5 at 08:10.

输入:

Each input file contains one test case. Each case starts with a line containing 4 positive integers: N (<=20, number of windows), M (<=10, the maximum capacity of each line inside the yellow line), K (<=1000, number of customers), and Q (<=1000, number of customer queries).

The next line contains K positive integers, which are the processing time of the K customers.

The last line contains Q positive integers, which represent the customers who are asking about the time they can have their transactions done. The customers are numbered from 1 to K.

输出:

For each of the Q customers, print in one line the time at which his/her transaction is finished, in the format HH:MM where HH is in [08, 17] and MM is in [00, 59]. Note that since the bank is closed everyday after 17:00, for those customers who cannot be served before 17:00, you must output "Sorry" instead.

样例输入:
2 2 7 5
1 2 6 4 3 534 2
3 4 5 6 7
样例输出:
08:07
08:06
08:10
17:00
Sorry
答疑:
解题遇到问题?分享解题心得?讨论本题请访问: http://t.jobdu.com/thread-8049-1-1.html

本题在浙大PAT上有同样的题目,但两个OJ对题目的解读并不同,区别在于对


“for those customers who cannot be served before 17:00, you must output


 ‘Sorry’ instead.”这句话的理解。


九度要求对于17点之前未处理完成的,一律为sorry。


浙大PAT上要求17:00之前如果开始处理,那么要给出处理完的时间。而对于还在排队


的,均为sorry。


下面是浙大PAT上AC的代码,九度上只需要稍微改动一下,大体思想相同,感觉类似CPU调度时的时间片轮转算法,

排队就是简单的FIFO。


#include<iostream>
#include<cstdio>
using namespace std;

class Lineitem
{
public:
	int trans;
	int no;
};

Lineitem line[22][12];

int cus[1002];
int res[1002];

int main()
{
	freopen("input.in", "r", stdin);
	freopen("output.out","w", stdout);
	int n, m, k, q, i, j;

	int cusP = 0,time=0;

	cin >> n >> m >> k >> q;

	for (i=0; i<k; i++)
	{
		cin >> cus[i];
	}

	//队伍排满
	for (j=0; j<m; j++)
	{
		
		for (i=0; i<n; i++)
		{
			if (cusP>=k)//队伍无人
			{
				line[i][j].no = -1;
				line[i][j].trans = 0;
			}
			else
			{
				line[i][j].no = cusP;
				line[i][j].trans = cus[cusP++];
			}
		}
	}
	for (time=1; time<540; time++)
	{
		for (i=0; i<n; i++)
		{
			//本队无客户,去下一队
			if (line[i][0].no == -1)
			{
				continue;
			}

			line[i][0].trans--;//每个窗口同步服务当前客户
			//客户服务完毕,下一客户进队
			if (line[i][0].trans == 0)
			{
				res[line[i][0].no] = time;//记录当前客户完成时间
				//依次前移
				for (j=0; j<m-1; j++)
				{
					line[i][j] = line[i][j+1];
				}
				
				//新客户入队
				if (cusP<k)
				{
					line[i][j].no = cusP;
					line[i][j].trans = cus[cusP++];
				}
				else
				{
					//无新客户
					line[i][j].no = -1;
					line[i][j].trans = 0;
				}
			}
		}//end of for i
	}//end of for time
	//时间到,还在处理的处理完
	for (i=0; i<n; i++)
	{
		if (line[i][0].no != -1)
		{
			res[line[i][0].no] = time+line[i][0].trans-1;
		}
	}
	//还在队内sorry
	for (i=0; i<n; i++)
	{
		for (j=1; j<m; j++)
		{
			if (line[i][j].no==-1)
			{
				break;
			}
			res[line[i][j].no] = -1;
		}
	}//*/
	//还在黄线外sorry
	while (cusP<k)
	{
		res[cusP++] = -1;
	}

	int index;
	for (i=0; i<q; i++)
	{
		cin >> index;
		index--;
		if (res[index] == -1||n==0||m==0)
		{
			printf("Sorry\n");
		}
		else
		{
			printf ("%02d:%02d\n", res[index]/60+8, res[index]%60);
		}
	}
	return 0;
}


转载于:https://www.cnblogs.com/ymjia/p/3590300.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,根据提供的引用内容,我无法回答关于西北工业大学计算机考研真题在百度云上的问题。引用提供了一个关于字符串合并的样例输入和输出,而引用和引用提供了一些与西北工业大学计算机研究生的相关信息。但是,这些引用内容都没有提供与百度云相关的信息。如果您有关于其他方面的问题,我将很乐意为您提供帮助和回答。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [九度OJ 题目1471:合并符串](https://blog.csdn.net/SJF0115/article/details/8609716)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [2021西北工业大学考研历年真题](https://blog.csdn.net/weixin_42502288/article/details/118177726)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [undefined](undefined)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值