1017. Queueing at Bank (25)

102 篇文章 0 订阅
29 篇文章 0 订阅

  
  

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
Sample Output:
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答案正确251017C++ (g++ 4.7.2)12436datrilla

测试点

测试点结果用时(ms)内存(kB)得分/满分
0答案正确118012/12
1答案正确13083/3
2答案正确13083/3
3答案正确13083/3
4答案正确13082/2
5答案正确124362/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[N];
  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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值