博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
pat1014. Waiting in Line (30)
阅读量:4968 次
发布时间:2019-06-12

本文共 3555 字,大约阅读时间需要 11 分钟。

1014. Waiting in Line (30)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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.

Input

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.

Output

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.

Sample Input
2 2 7 51 2 6 4 3 534 23 4 5 6 7
Sample Output
08:0708:0608:1017:00Sorry

 

教训:

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.

这句话的含义是如果不能在17:00之前开始服务,则输出“Sorry”

 

 

注意:vector就是可变长的动态数组,比较灵活好用

 

加入元素:push_back()

删除元素:用vector<int>::iterator   it  遍历至要删除的元素,然后v.erase(it)

元素个数:size()

访问元素:和一般的数组一样,直接访问

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 using namespace std; 8 struct custom{ 9 int cost,finish;10 };11 vector
v[21];12 custom cu[1005];13 int main(){14 //freopen("D:\\INPUT.txt","r",stdin);15 int n,m,k,q;16 scanf("%d %d %d %d",&n,&m,&k,&q);17 int i,j;18 for(i=0;i
::iterator it=v[minnum].begin();39 v[minnum].erase(it);40 v[minnum].push_back(i);41 }42 int num;43 for(i=0;i
17){49 continue;50 }51 int m=cu[num-1].finish%60;52 if(h>9){53 cout<
9){60 cout<

 

转载于:https://www.cnblogs.com/Deribs4/p/4708101.html

你可能感兴趣的文章
寻找二叉查找树中比指定值小的所有节点中最大的那个节点
查看>>
如何设置输入框达到只读效果
查看>>
RT3070 USB WIFI 在连接socket编程过程中问题总结
查看>>
MIS外汇平台荣获“2013年全球最佳STP外汇交易商”
查看>>
LeetCode 题解之Add Digits
查看>>
Xml处理工具类(Jdom)
查看>>
hdu1502 , Regular Words, dp,高精度加法
查看>>
20120227_CET6
查看>>
SpringBoot在idea中的热部署配置
查看>>
MyEclipse连接SQL Server 2008数据库的操作方法
查看>>
SqlCel 和MySQL for Excel在批量处理数据上的优劣
查看>>
leetcode【67】-Bulb Switcher
查看>>
JS验证图片格式和大小并预览
查看>>
调节心态的十种做法
查看>>
laravel5.2 移植到新服务器上除了“/”路由 ,其它路由对应的页面显示报404错误(Object not found!)———新装的LAMP没有加载Rewrite模块...
查看>>
潜罪犯
查看>>
编写高质量代码--改善python程序的建议(六)
查看>>
windows xp 中的administrator帐户不在用户登录内怎么解决?
查看>>
[spfa] Jzoj P4722 跳楼机
查看>>
代码审计入门后审计技巧
查看>>