国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

PAT_1017. Queueing at Bank

2019-11-08 20:10:57
字體:
來源:轉載
供稿:網友

這題只要到達時間在17:00:00之前,即使排隊輪到的時間超過17:00:00,仍然可以接受服務

// 1017_Queueing at Bank.cpp : 定義控制臺應用程序的入口點。//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#include "stdafx.h"#include "stdio.h"#include "iostream"#include "string.h"#include "stdlib.h"#include "string"#include "algorithm"using namespace std;struct custom{ string arrive; int time;}cus[10000];int spare_t[110];bool cmp(struct custom a, struct custom b){ return a.arrive<b.arrive;}int trans(string a){ int h = atoi(a.substr(0,2).c_str()); int m = atoi(a.substr(3,2).c_str()); int s = atoi(a.substr(6,2).c_str()); return h*3600+m*60+s;}int main(){ int n,k; while(cin>>n>>k){ for(int i = 0;i<n;i++){ cin>>cus[i].arrive>>cus[i].time; } sort(cus,cus+n,cmp); for(int i = 0;i<k;i++) spare_t[i] = trans("08:00:00"); float aver_t = 0.0; //結果 int cursor_cus = 0; //記錄當前隊伍中第一個顧客 int cursor_win = 0; //指示k個窗口中最早有空閑時間的 while(cursor_cus<n){ for(int i =0;i<k;i++){ if(spare_t[i]<spare_t[cursor_win]) cursor_win = i; } if(trans(cus[cursor_cus].arrive)<=trans("17:00:00")){ if(trans(cus[cursor_cus].arrive) >= spare_t[cursor_win]){ spare_t[cursor_win] = trans(cus[cursor_cus].arrive) + cus[cursor_cus].time*60; } else{ aver_t += spare_t[cursor_win] - trans(cus[cursor_cus].arrive); spare_t[cursor_win] += cus[cursor_cus].time * 60; } cursor_cus++; cursor_win = 0; } else break; } if(cursor_cus) printf("%.1lf/n",aver_t/((cursor_cus) * 60)); else cout<<"0.0"<<endl; } return 0;}/*c_str() 以 char* 形式傳回 string 內含字符串如果一個函數要求char*參數,可以使用c_str()方法: string s = "Hello World!";printf("%s", s.c_str()); //輸出 "Hello World!"*/
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 兴安盟| 罗平县| 平远县| 昌平区| 齐齐哈尔市| 宜丰县| 昔阳县| 延长县| 合川市| 布拖县| 宁南县| 诏安县| 武强县| 桓仁| 新田县| 乌拉特后旗| 湟源县| 寿宁县| 高台县| 九台市| 沙洋县| 合阳县| 司法| 东丽区| 霸州市| 高尔夫| 璧山县| 阜新市| 克山县| 大城县| 沾化县| 邢台市| 遵义县| 会宁县| 宿松县| 兰考县| 冀州市| 遵义县| 凌源市| 罗江县| 广丰县|