1026. Table Tennis (30)
来源:互联网 发布:淘宝问大家回答者删除 编辑:程序博客网 时间:2024/05/17 03:20
一道模拟题,做这种题先要模拟他的步骤,排队进场需要判断的两种情况,一种是队空的时候,有新的人到队列中;一种是队伍有人,球桌空出来了。用multiset表示时间轴,先把人到场时间放入multiset中,之后每处理一张桌就把,下次这张桌空的时间放入时间轴中,由于set是自动排好序的,所以就不停的时间流逝,直到时间轴为空或者时间轴的时间超过关门的时间,当然到每次时间轴的点,vip要先处理一下
需要注意的点:1.玩的时间不能超过2小时
2.算等待时间的时候要四舍五入
3.如果用s来代表时间,玩的时间要*60(细节)
#include<iostream>#include<deque>#include<algorithm>#include<set>#pragma warning(disable :4996)using namespace std;typedef struct player{//人 int arriving_time, serving_time, playing_time; bool vip; bool operator<(const player &that) const { return this->arriving_time < that.arriving_time; }}player;typedef struct table{ int time; int num; bool vip; table() :time(0), num(0), vip(false) {}}table;typedef struct timestamp {//时间轴 int time; bool player;//true代表队空,人到;false 代表队不空,桌空 timestamp(int t,bool x) :time(t),player(x) {} bool operator<(const timestamp that) const { if (this->time < that.time || (this->time == that.time && this->player == true)) return true; return false; }}timestamp;int N, K, M;void Print_P(player a){ int temp; if ((a.serving_time - a.arriving_time) % 60>=30) temp = 1; else temp = 0; printf("%02d:%02d:%02d %02d:%02d:%02d %d\n", a.arriving_time / 3600, a.arriving_time % 3600 / 60, a.arriving_time % 60, a.serving_time / 3600, a.serving_time % 3600 / 60, a.serving_time % 60, (a.serving_time - a.arriving_time) / 60 + temp);}int main(){ deque<player> ordinary, vip,all; deque<table> tab; multiset<timestamp> t_time; cin >> N; for (int t = 0;t < N;t++) { player temp; int h, m, s; scanf("%d:%d:%d %d %d", &h, &m, &s, &temp.playing_time, &temp.vip); temp.arriving_time = h * 3600 + m * 60 + s; if (temp.playing_time > 120)temp.playing_time = 120; temp.playing_time *= 60; t_time.insert(timestamp(temp.arriving_time,true)); all.push_back(temp); } cin >> K >> M; tab.resize(K); for (int t = 0;t < M;t++) { int temp; scanf("%d", &temp); tab[temp - 1].vip = true; } sort(all.begin(), all.end()); while (!t_time.empty()) { timestamp now = *t_time.begin();t_time.erase(t_time.begin()); if (now.time >= 21 * 3600) break; if (now.time < 8 * 3600) continue; if (now.player == true) { if (all.front().vip == true) vip.push_back(all.front()); else ordinary.push_back(all.front()); all.pop_front(); } for (auto &x : tab)//处理vip { if (vip.empty()) break; if (x.time <= now.time && x.vip) { x.num++; vip.front().serving_time = now.time; x.time = now.time + vip.front().playing_time; Print_P(vip.front()); vip.pop_front(); t_time.insert(timestamp(x.time,false)); } } //处理正常情况 bool flag; if (vip.empty() && !ordinary.empty()) flag = 0; else if (!vip.empty() && ordinary.empty()) flag = 1; else if (!vip.empty() && !ordinary.empty()) flag = vip.front() < ordinary.front() ? 1 : 0; else continue; for (auto &x : tab) { if (x.time <= now.time) { x.num++; if (flag == 0) { ordinary.front().serving_time = now.time; x.time = now.time + ordinary.front().playing_time; Print_P(ordinary.front()); ordinary.pop_front(); t_time.insert(timestamp(x.time,false)); } if (flag == 1) { vip.front().serving_time = now.time; x.time = now.time + vip.front().playing_time; Print_P(vip.front()); vip.pop_front(); t_time.insert(timestamp(x.time,false)); } if (vip.empty() && !ordinary.empty()) flag = 0; else if (!vip.empty() && ordinary.empty()) flag = 1; else if (!vip.empty() && !ordinary.empty()) flag = vip.front() < ordinary.front() ? 1 : 0; else break; } } } int f=0; for (auto x : tab) if (f == 0) { printf("%d", x.num);f++; } else printf(" %d", x.num); cout << endl;}
0 0
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- Redis 存储机制
- 操作系统下载
- JAVA8中Lambda表达式入门
- mybatis-日志(八)
- 使用python实现openvpn的登录次数限制
- 1026. Table Tennis (30)
- 七、三大特性~继承
- QT —— 应用程序发布
- JavaScript Good Parts学习笔记-第三章 对象
- Dagger2
- 作为类空超曲面里生活的我们
- 由DocumentsUI 得到文件path
- 基础——仿射变换矩阵与warpAffine
- POJ 1472Instant Complexity(模拟+dfs)