PTA A1014
A1014 Waiting in Line (30 分)题目内容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: Input Specification: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). Output Specification: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 5 Sample Output:08:07 单词transaction英 /tr?n‘z?k?(?)n; trɑ?n-; -‘s?k-/ 美 /tr?n‘z?k??n/ n. 交易;事务;办理;会报,学报 题目分析这道题我差不多前前后后做了四遍,给了我一些教训,首先是30分题一定要提前规划好程序,解决这个问题我们需要哪些数据,说出来有点尴尬,一开始这题我甚至没有用队列,另外一定要仔细读题,是17:00之后来的客人不服务,17:00之前来的客人就算是到半夜也要服务完。另外是Sorry,不是sorry! 具体代码从时间角度#include<stdio.h> #include<stdlib.h> #define MAXW 22 #define MAXQ 11 #define MAXP 1005 #define time int struct Queue { int q[MAXQ]; int length; int front; int rear; }; struct Window { time endtime; struct Queue queue; }; struct Person { time poptime; time dealtime; }; struct Window window[MAXW]; struct Person person[MAXP]; int N,M,K,Q; time nowtime = 0; void push_person(struct Queue *queue,int m) { queue->q[queue->rear] = m; queue->rear = (queue->rear + 1) % (M + 1); queue->length++; } int pop_person(struct Queue *queue) { int tmp = queue->q[queue->front]; queue->front = (queue->front + 1) % (M + 1); queue->length--; return tmp; } int find_min() { int tmp = -1; int min = 999; for (int i = 0; i < N; i++) { if (window[i].queue.length == 0) return i; if (window[i].queue.length != M && window[i].queue.length < min) { tmp = i; min = window[i].queue.length; } } return tmp; } int is_full() { for (int i = 0; i < N; i++) if (window[i].queue.length != M) return 0; return 1; } int is_empty() { for (int i = 0; i < N; i++) if (window[i].queue.length != 0) return 0; return 1; } void count_time() { int p = 1; while (p <= K) { if (!is_empty()) { for (int i = 0; i < N; i++) { if (person[window[i].queue.q[window[i].queue.front]].poptime + person[window[i].queue.q[window[i].queue.front]].dealtime == nowtime) pop_person(&window[i].queue); } } while (!is_full() && p <= K) { int min = find_min(); push_person(&window[min].queue,p); person[p].poptime = window[min].endtime; window[min].endtime += person[p].dealtime; p++; } nowtime++; } } int main(void) { scanf("%d %d %d %d",&N,&M,&K,&Q); for (int i = 1; i <= K; i++) scanf("%d",&person[i].dealtime); count_time(); for (int i = 0; i < Q; i++) { int q; scanf("%d",&q); if (person[q].poptime < 540) printf("%02d:%02dn",8+(person[q].poptime+person[q].dealtime)/60,(person[q].poptime + person[q].dealtime) % 60); else printf("Sorryn"); } system("pause"); } 从客户角度#include<stdio.h> #include<stdlib.h> #define MAXW 22 #define MAXQ 11 #define MAXP 1005 #define time int struct Queue { int q[MAXQ]; int length; int front; int rear; }; struct Window { time firsttime; time endtime; struct Queue queue; }; struct Person { time poptime; time dealtime; }; struct Window window[MAXW]; struct Person person[MAXP]; int N,Q; void push_person(struct Queue *queue,int m) { queue->q[queue->rear] = m; queue->rear = (queue->rear + 1) % (M + 1); queue->length++; } int pop_person(struct Queue *queue) { int tmp = queue->q[queue->front]; queue->front = (queue->front + 1) % (M + 1); queue->length--; return tmp; } int find_min() { int push = 0; for (int i = 0; i < N; i++) { if (window[i].firsttime < window[push].firsttime) push = i; } return push; } void count_time() { int p = 1; while (p <= K) { int push; if (p <= M * N) push = (p - 1) % N; else push = find_min(); if (window[push].queue.length == M) { pop_person(&window[push].queue); window[push].firsttime += person[window[push].queue.q[window[push].queue.front]].dealtime; } push_person(&window[push].queue,p); if (window[push].queue.length == 1) window[push].firsttime += person[window[push].queue.q[window[push].queue.front]].dealtime; person[p].poptime = window[push].endtime; window[push].endtime += person[p].dealtime; p++; } } int main(void) { scanf("%d %d %d %d",(person[q].poptime + person[q].dealtime) % 60); else printf("sorryn"); } system("pause"); } 参考博客1014 Waiting in Line (30 point(s)) - C语言 PAT 甲级 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- windows-server-2008-r2 – Win2k8R2获取DHCPv6地址,但具有
- Win2008 Server配置PHP环境 Win2008 Server配置
- windows-7 – 在计划任务中由UAC阻止的exe.exe名称
- WPF:从Window继承
- windows-server-2008 – 如何整合来自不同服务器的所有事件
- cnpm安装过程中提示optional install error: Package requi
- windows-server-2008 – 向Jr. SysAdmin解释当PC加入Window
- 在Windows中使用SSH服务器,无法找到共享库
- windows-installer – 如何根据需要安装和/或重新安装msiex
- XAML中的中心弹出窗口
- PyCharm 安装教程(Windows)
- wpf – 为什么要在XAML Window.Loaded调用的方法
- windows-server-2008-r2 – IPv6主机不响应Neigh
- windows-server-2003 – 将Perfmon计数器名称放入
- windows – 作为SCSI连接的网络驱动器在较大的文
- windows-8 – 为Xbox One开发应用程序?
- lodctr /R 失败的情况
- windows-server-2008 – 这是Windows Server 200
- 如何从.NET应用程序启动`powercfg.exe -energy`?
- 如何在安装时更改Windows Server 2012密码要求?