PAT(甲级)1014笔记--银行业务问题
2020-02-06 09:40
429 查看
PAT(甲级)1014笔记
1. 原题参照PAT官网
- 这道题就是很有趣很难得亚子,花费了不少时间
- 学习了这里的代码 【代码传送门】
2. 代码record
#include<stdio.h> #include<stdlib.h> #include<string> #include<queue> #include<stack> #include<iostream> #include<algorithm> using namespace std; #define MAXSIZE 30 const int maxn = 22;/////////????? const int maxk = 1000 + 10;///???? int N = 2, M = 0, K, Q, customer_key[1000], customer_time[1000]; int nowTime = 0; int CloseTime = (17 - 8) * 60; struct customer { int id; int processtime; int donetime; customer() :donetime(-1) {} }customers[maxk]; queue<customer> line[maxn], behindQueue; int lastTime[maxn] = { 0 }; int main() { scanf("%d%d%d%d", &N, &M, &K, &Q); int capacity = N * M; for (int i = 1; i <= K; i++) { scanf("%d", &customers[i].processtime);//输入每个人需要多长时间去办理业务 customers[i].id = i; //为用户id编号 if (i <= capacity) { line[(i - 1) % N + 1].push(customers[i]); ///啊这里是循环把前面第一波先到达的人放入队列中 } else behindQueue.push(customers[i]); ////之后来的人都放入后面的队列里面去 } int countC = K; //k是客户数量,Q是客户查询数量 while (nowTime < CloseTime&&countC) { //如果没到营业时间而且还有顾客来 nowTime++; //每分钟更新一次系统????像是一个计时器 for (int i = 1; i <= N; i++) { //每个队伍都查看一遍 if (!line[i].empty()) { //如果该队伍不是空的 int donetime = line[i].front().processtime + lastTime[i]; //??????结束时间等于过程所需时间+上一个人时间?? int id = line[i].front().id; //更新一下下一个要执行服务的id if ((donetime>CloseTime||donetime==nowTime)&&lastTime[i]<nowTime) //如果现在就是当前窗口正在办理的顾客的结束时间且lasttime<nowtime { customers[id].donetime = donetime; //给队首顾客结束时间; lastTime[i] = donetime; //lasttime就是上一个人结束的时间??? /*!!!!!!!*/ {line[i].pop(); //第一个顾客出去开始办理业务 countC--; //需要办理业务的顾客数量减少 if (behindQueue.size()) //把后面长队的人调入前面 { line[i].push(behindQueue.front()); behindQueue.pop(); }} } else if (lastTime[i] >= nowTime) { // line[i].pop(); countC--; if (behindQueue.size()) { line[i].push(behindQueue.front()); behindQueue.pop(); } } } } } int query; for (int i = 0; i < Q; i++) { scanf("%d", &query); if (customers[query].donetime != -1) printf("%02d:%02d\n", 8 + customers[query].donetime / 60, customers[query].donetime % 60); else printf("sorry\n"); } return 0; }
然后我觉得还有第二种方法,但不知道为什么编译出问题了。有时间的话在重新研究一i下,毕竟这个才是自己想出来的思路,,上面是依照网络纠正得。
#include<stdio.h> #include<stdlib.h> #include<string> #include<queue> #include<stack> #include<iostream> #include<algorithm> using namespace std; #define MAXSIZE 30 const int maxn = 21; const int maxk = 1005; int N, M, K, Q; struct customer { int id, servertime; int begintime, endtime; customer() :begintime(0), endtime(-1), servertime(0), id(0) {}; }cus[maxk]; queue<customer>line[maxn], wait; int main() { cin >> N >> M >> K >> Q; //int line_in = N * M; for (int i = 1; i <= K; ++i) { cin >> cus[i].servertime; cus[i].id = i; if (i<=N) cus[i].endtime = cus[i].servertime; if (i<=N*M)line[(i - 1) % N + 1].push(cus[i]); else wait.push(cus[i]); } int countC = K; int nowtime = 0, closetime = (17 - 8) * 60; while (nowtime < closetime && countC) { nowtime++; for (int j = 1; j <= N; ++j){ if (line[j].empty()) { continue; } customer head = line[j].front(); if (head.endtime <= nowtime || head.endtime > closetime) { line[j].pop(); countC--; line[j].front().begintime = head.endtime; line[j].front().endtime = head.endtime + line[j].front().servertime; cus[head.id].begintime = head.begintime; cus[head.id].endtime = head.endtime; if (!wait.empty()) { line[j].push(wait.front()); wait.pop(); } } } }; int q; for (int i = 1; i <= Q; i++){ cin >> q; if (cus[q].endtime == -1)cout << "sorry" << endl; else printf("%02d:%02d\n", cus[q].endtime / 60 + 8, cus[q].endtime % 60); } return 0; }
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- PAT甲级解题笔记1004-dfs/树的遍历
- PAT basic-level 1014 福尔摩斯的约会 笔记
- PAT(甲级)1017笔记
- PAT - 甲级 - 1128. N Queens Puzzle (20) (8皇后问题变形)
- PAT程序设计考题——甲级1008(Elevator电梯时间计算问题)
- PAT甲级1015笔记记录 测试点3未通过
- PAT 甲级1014 Waiting in Line
- PAT成长之路——乙级链表类问题笔记
- PAT程序设计考题——甲级1068 (背包问题) C++实现
- PAT甲级 1014
- PAT程序设计考题——甲级1014( Waiting in Line ) C++实现
- pat甲级_路径问题(例题:pat 1003 Emergency (25))
- PAT甲级1003---迷宫问题(DFS或Dijkstra)
- PAT甲级解题笔记1079-dfs/树的遍历
- PAT程序设计考题——甲级1006 签到问题(求所有签到人的最早时间和最晚时间)
- PAT 甲级 1014 Waiting in Line (30)
- PAT甲级 1095 Cars on Campus(超时问题的过来看看)
- 1049. Counting Ones (30)-PAT甲级真题(数学问题)
- 【note】PAT甲级刷题笔记
- **甲级PAT1014 Waiting in Line (已经通过全部测试,找到一个奇怪的坑但是不知道为什么,跪求大佬回复)