zoukankan      html  css  js  c++  java
  • PAT 1017 Queueing at Bank (25) (坑题)

    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
    

     题意:银行排队,有 n 个人 m 个窗口,银行营业只在8.00-17.00,对于17.00后来的不给服务,对17.00前的都给服务,即使是超过了17.00,这是一个大坑,没有看出来感觉题目并没有说清楚,知道了这个,用优先队列直接模拟就好,其他的都很简单。

    析:先按来的时间排序,然后用优先队列进行模拟。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #include <sstream>
    #define debug() puts("++++");
    #define gcd(a, b) __gcd(a, b)
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define freopenr freopen("in.txt", "r", stdin)
    #define freopenw freopen("out.txt", "w", stdout)
    using namespace std;
    
    typedef long long LL;
    typedef unsigned long long ULL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const LL LNF = 1e17;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 1e4 + 10;
    const int mod = 1000000007;
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, 1, 0, -1};
    const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline bool is_in(int r, int c){
      return r >= 0 && r < n && c >= 0 && c < m;
    }
    
    const int before = 8 * 60 * 60;
    const int after = 17 * 60 * 60;
    struct Node{
      int s, w;
      bool operator < (const Node &p) const{
        return s < p.s;
      }
    };
    Node a[maxn];
    
    int main(){
      scanf("%d %d", &n, &m);
      for(int i = 0; i < n; ++i){
        int h, s, m;
        scanf("%d:%d:%d %d", &h, &m, &s, &a[i].w);
        a[i].s = h * 3600 + m * 60 + s;
        a[i].w *= 60;
      }
      int sum = 0, cnt = 0;
      sort(a, a + n);
      priority_queue<int, vector<int>, greater<int> > pq;
      for(int i = 0; i < m; ++i) pq.push(before);
      int i = 0;
      while(i < n){
        int x = pq.top();  pq.pop();
        if(a[i].s > after)  break;
        if(x >= a[i].s){
          sum += x - a[i].s;
          x += a[i].w;
        }
        else x = a[i].s + a[i].w;
        ++cnt;
        ++i;
        pq.push(x);
      }
      if(cnt == 0)  printf("0.0
    ");
      else printf("%.1f
    ", sum / 60.0 / cnt);
      return 0;
    }
    

      

  • 相关阅读:
    【spring cloud】spring cloud服务发现注解之@EnableDiscoveryClient与@EnableEurekaClient
    【IntelliJ IDEA】idea导入项目只显示项目中的文件,不显示项目结构
    【IntelliJ IDEA】idea显示工具栏
    笔记:git基本操作
    Spring Boot中使用AOP统一处理Web请求日志
    Spring Boot应用的后台运行配置
    RSA加密
    Java汉字md5值不一致问题
    如何判断一个请求是不是ajax请求
    SpringBoot拦截器中service或者redis注入为空的问题
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/7217305.html
Copyright © 2011-2022 走看看