1017. Queueing at Bank (25)
2015-07-29 10:20
441 查看
Sample Output:1017. Queueing at Bank (25)
时间限制400 ms 内存限制65536 kB 代码长度限制16000 B 判题程序Standard作者CHEN, Yue Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is his/her turn to be served and there is a window available. It is assumed that no window can be occupied by a single customer for more than 1 hour.Now given the arriving time T and the processing time P of each customer, you are supposed to tell the average waiting time of all the customers.Input Specification:Each input file contains one test case. For each case, the first line contains 2 numbers: N (<=10000) - the total number of customers, and K (<=100) - the number of windows. Then N lines follow, each contains 2 times: HH:MM:SS - the arriving time, and P - the processing time in minutes of a customer. Here HH is in the range [00, 23], MM and SS are both in [00, 59]. It is assumed that no two customers arrives at the same time.Notice that the bank opens from 08:00 to 17:00. Anyone arrives early will have to wait in line till 08:00, and anyone comes too late (at or after 17:00:01) will not be served nor counted into the average.Output Specification:For each test case, print in one line the average waiting time of all the customers, in minutes and accurate up to 1 decimal place.Sample Input:7 3 07:55:00 16 17:00:01 2 07:59:59 15 08:01:00 60 08:00:00 30 08:00:02 2 08:03:00 10
8.2
这题和http://xujiayu317.blog.163.com/blog/static/25475209201562611122716/ 有点像,区别在于,这题每个窗口黄线内仅有一名,且这题算的是等待时间。
所有的窗口的初始时间为早上8点,来的如果在CloseTime 61201 秒=17:00:1或之后均不会被服务,所以在输入中就比较排除(其余都会被服务,即使轮到的时候在 CloseTime或之后PS:这里我测试了轮到的时间如果超过或等于CloseTime就停止会测试点一个错误 2015-7-29.不知道以后数据会不会更新),处理时间有超过60分钟的强制60分钟。
按时间先来后到排序, 用到头文件#include<algorithm> sort(QB, QB + N, QBCMp);
之后循环找到最早有人处理结束的那个窗口,然后有两种情况,
一种轮到的这个来得早了,他需要等待waitsum+等待时间,且这个窗口下个空期=窗口的当前空期+这个人的costtime;
另一种轮到的这个来得晚了或等于,无需等待,且这个窗口下个空期=这个人来的时间+这个人的costtime;
PS:我用的编译软件是vs2013community,
用 scanf("%d:%d:%d%d", &h, &m, &s, &pocesstime);我的编译软件提示错误,不安全,但是提交到测试平台可以通过。
我的编译器修改成scanf_s("%d:%d:%d%d", &h, &m, &s, &pocesstime);可以通过,但是在测试平台编译错误 error: 'scanf_s' was not declared in this scope。 对此 目前还不是很清楚应该怎样,百度了一下,说是需要提供参数大小。
所以我就用了cin,只是多弄了char ,两个地方都可以通过。
查看提交
评测结果
时间 | 结果 | 得分 | 题目 | 语言 | 用时(ms) | 内存(kB) | 用户 |
---|---|---|---|---|---|---|---|
7月29日 09:45 | 答案正确 | 25 | 1017 | C++ (g++ 4.7.2) | 12 | 436 | datrilla |
测试点
测试点 | 结果 | 用时(ms) | 内存(kB) | 得分/满分 |
---|---|---|---|---|
0 | 答案正确 | 1 | 180 | 12/12 |
1 | 答案正确 | 1 | 308 | 3/3 |
2 | 答案正确 | 1 | 308 | 3/3 |
3 | 答案正确 | 1 | 308 | 3/3 |
4 | 答案正确 | 1 | 308 | 2/2 |
5 | 答案正确 | 12 | 436 | 2/2 |
#include<iostream> #include<algorithm> #include<iomanip> #define CloseTime 61201 #define StarTime 28800 using namespace std; struct QueueingAtBank { int ComeTime; int costTime; }; int Init(QueueingAtBank*QB,int N) { int h, m, s, pocesstime,index,TheIndex; char c; for (index = 0, TheIndex = 0; index < N; index++) { cin >> h >> c >> m >> c >> s >> pocesstime; h = h * 3600 + m * 60 + s; if (h <CloseTime) { pocesstime = pocesstime > 60 ? 60 : pocesstime; QB[TheIndex].ComeTime = h; QB[TheIndex].costTime = pocesstime*60; TheIndex++; } } return TheIndex; } void Starclear(int*windows, int StAr, int EnD, int Y_Y) { for (; StAr < EnD; StAr++) windows[StAr] = Y_Y; } bool QBCMp(const QueueingAtBank &A, const QueueingAtBank &B) { return A.ComeTime < B.ComeTime; } float QueueBank(QueueingAtBank*QB,int *windows,int N,int K) { int index, EmptYwindow, TheIndex,i; float waitSum; waitSum = 0.0; for (index = 0; index < N; index++) { TheIndex = 0; EmptYwindow = windows[0]; for (i = 1; i < K; i++) { if (windows[i] < EmptYwindow) { TheIndex = i; EmptYwindow = windows[i]; } } if (EmptYwindow>QB[index].ComeTime) { waitSum += EmptYwindow - QB[index].ComeTime; windows[TheIndex] += QB[index].costTime; } else { windows[TheIndex] = QB[index].ComeTime + QB[index].costTime; } } return waitSum; } int main() { int N, K; QueueingAtBank*QB; int *windows; cin >> N >> K; QB = new QueueingAtBank ; windows = new int[K]; Starclear(windows, 0, K, StarTime); N = Init(QB, N); sort(QB, QB + N, QBCMp); cout << setiosflags(ios::fixed) << setprecision(1) << QueueBank(QB, windows, N, K) / N / 60 << endl; system("pause"); delete[]windows; delete[]QB; return 0; }
相关文章推荐
- INSTALL_FAILED_UID_CHANGED解决办法
- UILabel文本控件(转)
- UICollectionView中关于DecorationView的使用
- Easyui的validatebox验证方法自定义扩展
- hibernate里createSQLQuery的addEntity()和setResultTransformer()方法
- UITextField输入文字下浮问题及更改模态视图导航条样式
- UILabel高度自适应
- Seek the Value in Requested Capabilities
- IOS开发UI篇--动画(Core Animation)总结
- 源码推荐(7.29):iOS图片查看器(多图全屏查看可缩放),给UITextView 添加超链接
- Android项目生成build.xml
- iOS开发,UI学习之UILabel用法详解
- UITableViewCell的选中时的颜色设置
- poj-2524 Ubiquitous Religions
- vs2008 HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ MSBuild \ ToolsVersions \ 14.0
- According to TLD or attribute directive in tag file, attribute value does not accept any expressions
- ios开发之 用UILabel显示html
- Snail—UI学习之滑块UISlider
- UI-动画
- EF6 CodeFirst+Repository+Ninject+MVC4+EasyUI实践(六)