当前位置:网站首页>Pat grade a 1026 table tennis
Pat grade a 1026 table tennis
2022-06-27 02:51:00 【IX. non random address】
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
#include<queue>
using namespace std;
struct pairer{
int timestamp;
int playtime;
int waittime;
int start;
int leave;
int tablenum;
int vip;
};
bool compare(const pairer& a, const pairer& b){
if(a.timestamp < b.timestamp) return true;
else return false;
}
bool compare_cc(const pairer& a, const pairer& b){
if(a.start < b.start) return true;
else return false;
}
int minleave(vector<pairer> &c){
int minval = 99999999;
int i, k;
for(i=0; i<c.size(); i++){
if(minval > c[i].leave) {
minval = c[i].leave;
k = i;
}
}
return k;
}
int main(void){
int i, j, m, n, k, h, hour, min, sec, t0, t6;
pairer pr, pr0, pr6;
vector<pairer> v, vr;
set<int> vipset;
vector<int> vipvec;
cin>>n;
int mn;
for(i=0; i<n; i++){
scanf("%d:%d:%d %d %d", &hour, &min, &sec, &mn, &pr.vip);
if(mn > 120){ mn = 120; }
pr.playtime = mn * 60;
pr.timestamp = hour * 3600 + min * 60 + sec;
if(pr.timestamp < (3600 * 8)) continue;
if(pr.timestamp >= (3600 * 21)) continue;
v.push_back(pr);
}
cin>>k>>m;
for(i = 0; i < m; i++){
cin>>h;
vipvec.push_back(h);
vipset.insert(h);
}
sort(v.begin(), v.end(), compare);
vector<pairer> pq;
for(int i = 0; i < k; i++) {
pr.timestamp = 8 * 3600;
pr.playtime = 0;
pr.waittime = 0;
pr.leave = 8 * 3600;
pr.tablenum = i + 1;
pq.push_back(pr);
}
int leave, counts = 0, ind, tabnum, mar;
set<int>::iterator it, it0;
set<int> vipserve;
for(i = 0; i < v.size(); i++){
it0 = vipserve.find(i);
if(it0!=vipserve.end()) continue;
ind = minleave(pq);
tabnum = pq[ind].tablenum;
it = vipset.find(tabnum);
mar = 999;
if(it!=vipset.end()){
for(j = i + 1; j < v.size(); j++){
it0 = vipserve.find(j);
if(it0!=vipserve.end()) continue;
if(v[j].vip==1){
pr = pq[ind];
if(pr.leave > v[j].timestamp){ //waitting
v[j].leave = pr.leave + v[j].playtime; //pre leave + now playing
v[j].start = pr.leave;
v[j].waittime = pr.leave - v[j].timestamp;
v[j].tablenum = pr.tablenum;
pq.push_back(v[j]);
pr0 = v[i];
pr6 = v[j];
v.erase(v.begin() + i);
v.erase(v.begin() + j - 1);
v.insert(v.begin() + i, pr6);
v.insert(v.begin() + i + 1, pr0);
pq.erase(pq.begin() + ind);
vipserve.insert(i);
mar = -999;
break;
}
}
}
}
if(mar < 0) continue;
pr = pq[ind];
if(pr.leave > v[i].timestamp){ //waitting
v[i].leave = pr.leave + v[i].playtime; //pre leave + now playing
v[i].start = pr.leave;
v[i].waittime = pr.leave - v[i].timestamp;
v[i].tablenum = pr.tablenum;
pq.erase(pq.begin() + ind);
}else{ //no waitting
int minmin = 9999999;
for(int ij = 0; ij < pq.size(); ij++){ //check someplace no people table
if(pq[ij].leave <= v[i].timestamp && pq[ij].tablenum < minmin){
minmin = pq[ij].tablenum;
ind = ij;
}
}
pr = pq[ind];
v[i].leave = v[i].timestamp + v[i].playtime;
v[i].start = v[i].timestamp;
v[i].waittime = 0;
v[i].tablenum = pr.tablenum;
pq.erase(pq.begin() + ind);
}
if(v[i].vip==1) vipserve.insert(i);
pq.push_back(v[i]);
}
sort(v.begin(), v.end(), compare_cc);
string str0, str6;
int cal, cal0, cal6;
int tablecount[k] = {0};
for(int i = 0; i < v.size(); i++){
cal = v[i].timestamp;
cal0 = v[i].start;
cal6 = v[i].waittime;
if(v[i].start >= (3600 * 21)) continue;
printf("%02d:%02d:%02d %02d:%02d:%02d %d\n",
cal/3600, (cal%3600)/60, (cal%3600)%60,
cal0/3600, (cal0%3600)/60, (cal0%3600)%60,
(int)round((float)cal6/60.0));
tablecount[v[i].tablenum - 1]++;
}
for(int i = 0; i < k; i++){
cout<<tablecount[i];
if(i!=(k-1)) cout<<" ";
}
return 0;
}边栏推荐
- Logarithm
- Constraintlayout Development Guide
- 2022 Chinese pastry (Advanced) recurrent training question bank and online simulation test
- Oracle/PLSQL: NumToYMInterval Function
- Record the method of reading excel provided by unity and the solution to some pits encountered
- 超级详细,2 万字详解,吃透 ES!
- TP5 Spreadsheet Excle 表格导出
- paddlepaddle 19 动态修改模型的最后一层
- How do I simplify the development of interfaces in open source systems?
- LeetCode 785:判断二分图
猜你喜欢

How does source insight (SI) display the full path? (do not display omitted paths) (turn off trim long path names with ellipses)

Would rather go to 996 than stay at home! 24 years old, unemployed for 7 months, worse than work, no work

pytorch 22 8种Dropout方法的简介 及 基于Dropout用4行代码快速实现DropBlock

Google began to roll itself, AI architecture pathways was blessed, and 20billion generation models were launched

PAT甲级 1018 Public Bike Management

Look! In June, 2022, the programming language ranking list was released! The first place is awesome

C language -- Design of employee information management system

1、项目准备与新建

Flink learning 5: how it works

TechSmith Camtasia latest 2022 detailed function explanation Download
随机推荐
Cvpr2022 | pointdistiller: structured knowledge distillation for efficient and compact 3D detection
jwt的认证流程和使用案例
超级详细,2 万字详解,吃透 ES!
Canvas particles: mouse following JS effect
pytorch_ grad_ Cam -- visual Library of class activation mapping (CAM) under pytorch
How do I simplify the development of interfaces in open source systems?
Mmdetection valueerror: need at least one array to concatenate solution
TechSmith Camtasia最新2022版详细功能讲解下载
"All majors are persuading them to quit." is it actually the most friendly to college students?
【一起上水硕系列】Day 6
Flink学习1:简介
我是怎样简化开源系统中的接口的开发的?
QIngScan使用
Flink learning 3: data processing mode (stream batch)
学习太极创客 — MQTT(七)MQTT 主题进阶
PAT甲级 1023 Have Fun with Numbers
three.js多米诺骨牌js特效
DAMA、DCMM等数据管理框架各个能力域的划分是否合理?有内在逻辑吗?
mmdetection 用yolox训练自己的coco数据集
Super détaillé, 20 000 caractères détaillés, mangez à travers es!
https://github.com/ZouJiu1/PAT