蛮复杂的一道模拟题
需要注意的点挺多的:
1.优先级问题(vip桌子的安排)
2.playtime规定在2h之内,超过2h按2h计算
3.servingtime等于或大于21点的不输出

#include <iostream>
#include <stdio.h>
#include<stdlib.h>
#include <string>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <string.h>
#include <map>
#include <set>using namespace std;
int N, Pt,h,m,s,tag, K, M, ind,pi,vi;typedef struct player
{int atime;int ptime;int stime;int wtime;
};
player P[10010];
player V[10010];typedef struct table {int index;int stime;int players;int tag;
};
table T[110];bool cmp1(player a,player b)
{return a.atime < b.atime;
}bool cmp2(player a, player b)
{return a.stime < b.stime;
}bool cmp3(table a, table b)
{if(a.stime != b.stime)return a.stime<b.stime;else return a.index < b.index;
}bool cmp4(table a, table b)
{return a.index < b.index;
}vector <int> vip_table;int main()
{#ifdef  LIUFILE *ss;freopen_s(&ss, "1.txt", "r", stdin);
#endif cin >> N;int open = 8 * 3600;int close = 21 * 3600;char c;vi = 0; pi = 0;for (int i = 0; i < N; i++){cin >> h >> c >> m >> c >> s;cin >> Pt>>tag;if (tag == 1){V[vi].atime= h * 3600 + m * 60 + s;V[vi].ptime = min(120*60,Pt*60);vi++;}else {P[pi].atime= h * 3600 + m * 60 + s;P[pi].ptime = min(120*60,Pt*60);pi++;}}sort(P, P + pi, cmp1);//按player到达时间排序sort(V, V + vi, cmp1);cin >> K >> M;for (int i = 0; i < K; i++){if (i < M) {cin >> ind;T[ind - 1].tag = 1;//数组中编号为0-K-1vip_table.push_back(ind-1);}T[i].index = i + 1;T[i].players = 0;T[i].stime = open;}sort(vip_table.begin(), vip_table.end());//安排前K个顾客中的vip若N<K,则安排前N个int posv = 0,posp=0;int otable = 0;int vtable = 0;for (int t = 0; t < K; t++){if (posv + posp == N)break;if (posv < vi&&(posp==pi||V[posv].atime < P[posp].atime)){//是vip先检测有无空闲的vip桌子if(vtable<M){V[posv].stime = V[posv].atime;V[posv].wtime = 0;T[vip_table[vtable]].stime = V[posv].stime + V[posv].ptime; if (V[posv].stime < close) {T[vip_table[vtable]].players++;}vtable++;}else {while (T[otable].tag==1) {++otable;}V[posv].stime = V[posv].atime;V[posv].wtime = 0;T[otable].stime = V[posv].stime + V[posv].ptime;if (V[posv].stime < close) {T[otable].players++;}otable++;}posv++;}else if (posp < pi){while(T[otable].tag == 1&& (vtable==M||otable < vip_table[vtable]))otable++;if (T[otable].tag == 1) vtable++;P[posp].stime = P[posp].atime;P[posp].wtime = 0;T[otable].stime = P[posp].stime + P[posp].ptime;if (P[posp].stime < close) {T[otable].players++;}otable++;posp++;}}while (posp + posv < N)//顾客没有安排完{sort(T, T + K, cmp3);if (T[0].tag == 1&&posv<vi && V[posv].atime <= T[0].stime)//是vip桌子{//看队列中有没有vipV[posv].stime = T[0].stime;V[posv].wtime = (V[posv].stime - V[posv].atime+30) / 60;if (V[posv].stime < close) {T[0].stime += V[posv].ptime;T[0].players++;}posv++;}else{//给顺次下一位顾客安排桌子if (posp<pi&&(posv==vi||P[posp].atime < V[posv].atime)){  //一般顾客P[posp].stime = max(P[posp].atime,T[0].stime);P[posp].wtime = (P[posp].stime-P[posp].atime+30)/60;T[0].stime = P[posp].stime + P[posp].ptime;if (P[posp].stime < close) {T[0].players++;}posp++;}else{V[posv].stime = max(V[posv].atime,T[0].stime);V[posv].wtime = (V[posv].stime - V[posv].atime+30) / 60;T[0].stime = V[posv].stime + V[posv].ptime;if (V[posv].stime < close) {T[0].players++;}posv++;}}}sort(P, P + pi, cmp2);//按player服务时间排序sort(V, V + vi, cmp2);posp = posv = 0;while (posp+posv<N){if (posp<pi&&(posv == vi || P[posp].stime < V[posv].stime)){if (P[posp].stime < close) {printf("%02d:%02d:%02d %02d:%02d:%02d %d\n",P[posp].atime / 3600, (P[posp].atime % 3600) / 60, P[posp].atime % 60,P[posp].stime / 3600, (P[posp].stime % 3600) / 60, P[posp].stime % 60,P[posp].wtime);}++posp;}else {if (V[posv].stime < close) {printf("%02d:%02d:%02d %02d:%02d:%02d %d\n",V[posv].atime / 3600, (V[posv].atime % 3600) / 60, V[posv].atime % 60,V[posv].stime / 3600, (V[posv].stime % 3600) / 60, V[posv].stime % 60,V[posv].wtime);}++posv;}           }sort(T, T + K, cmp4);for (int t = 0; t < K; t++){  if (t == 0) cout << T[t].players;else cout << ' ' << T[t].players;}cout << endl;return 0;
}

PAT 1026 Table Tennis (30分)相关推荐

  1. 【PAT甲级 模拟 测试点0、3、4、5、7、8分析】1026 Table Tennis (30 分)

    这篇文章帮我解决了测试点5.7 测试点分析都在代码注释里了 #include<bits/stdc++.h> using namespace std;int N, K, M; // 球友对的 ...

  2. 1026 Table Tennis (30分)

    据说是PAT最难的一道模拟题,情况很复杂,第二次做了,依旧是折磨人的小妖精(* ̄︶ ̄). 这次主要是栽在条件判断上了,一定要小心数组越界!而且这种错很难找 (代码里※标注的地方,就是我找错找了好久的地 ...

  3. 1026 Table Tennis (30 分) 未完成【难度: 难 / 知识点: 模拟】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805472333250560

  4. 1026. Table Tennis (30)

    题目如下: A table tennis club has N tables available to the public. The tables are numbered from 1 to N. ...

  5. PAT甲级1147 Heaps (30 分):[C++题解]堆、树的遍历、dfs、完全二叉树建树

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析:给定完全二叉树,判断是否是堆,需要区分大根堆,小根堆.后面是输出后序遍历. AC代码 #include<bits/stdc++. ...

  6. 1026 Table Tennis Python实现

    1026 Table Tennis Python实现 1.占用时间不能超过两小时 2.vip优先选择vip空桌,而非编号最小的空桌 def stot(w:str):h=int(w[:2])m=int( ...

  7. 1026 Table Tennis (30 分)模拟排列问题

    题目 A table tennis club has N tables available to the public. The tables are numbered from 1 to N. Fo ...

  8. PAT甲级1139 First Contact (30 分):[C++题解] 图论、暴力枚举两个点、hash映射

    文章目录 题目分析 题目链接 题目分析 来源:acwing 题目分析: 图论模拟题. 给定暗恋的两个人A 和B,需要寻找一对C 和D ,满足:A和C是朋友,C和D是朋友,D和B是朋友.而且A.C同性别 ...

  9. PAT甲级1087 All Roads Lead to Rome (30分):[C++题解]dijkstra求单源最短路综合、最短路条数、保存路径

    文章目录 题目分析 题目链接 题目分析 来源:acwing 分析: 首先这是一道dijkstra算法求最短路的题目,不过此题较为复杂.首先需要将字符串城市名映射成数字,这里使用hash table 名 ...

最新文章

  1. 寒假挑战PythonTip(一人一python)总结——算法是程序的灵魂,程序员的心法
  2. HDU1151 Air Raid
  3. 如何发布自己的 Composer 包
  4. linux pclint配置_静态分析工具PC-lint Plus使用教程:安装与配置
  5. aardio中获取网络图片经GDI处理后保存到本地
  6. python中self和cls的区别
  7. image转base64
  8. 机器学习之MCMC算法
  9. 【算法动画图解】:安利一款昨天发现的app
  10. PPC手机上网设置大全
  11. php swfobject,swfobject参数详细介绍
  12. linux手机拍照翻译软件,有没有直接拍照就可以翻译的软件-拍照翻译app哪个好用...
  13. 基于Zynq的光流法软硬件协同实现
  14. STM32与jink连接烧录程序
  15. php判断是否是全英文,php判断字符串是否全英文,纯中文,中英文组合的方法
  16. DB buffer bussy wait 分析一例
  17. PC端-中文转拼音后续问题
  18. Jetson Nano | darknet (yolov3.4-tiny)摄像头实时检测
  19. 七天学习微信小程序开发(一)—— 学习笔记
  20. 入侵检测技术综述(比较全)

热门文章

  1. 神经系统的区分图解高中,神经系统的区分和组成
  2. 西北乱跑娃 --- 易语言大文件读取
  3. 异常处置规则_如何负责任地处置旧计算机
  4. circular 字体_DebevicCircular字体ttf下载 最新版
  5. 侃谈移动端音视频发展与现状
  6. android图片缩放的处理方式
  7. 王者荣耀助手动态服务器维护中,王者荣耀助手动态怎么发不了 | 手游网游页游攻略大全...
  8. Linux系统安装网卡驱动
  9. 【报告分享】阿里研究院:2020中国淘宝村研究报告(附下载)
  10. 超好用的鼠标增强软件:Smooze for Mac