当前位置:网站首页>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;
}边栏推荐
- Hot discussion: what are you doing for a meaningless job with a monthly salary of 18000?
- How does source insight (SI) display the full path? (do not display omitted paths) (turn off trim long path names with ellipses)
- Flink learning 2: application scenarios
- Flink learning 3: data processing mode (stream batch)
- Laravel 的 ORM 缓存包
- Oracle/PLSQL: NumToYMInterval Function
- Flink learning 5: how it works
- 1. Project preparation and creation
- C# Tcp服务器如何限制同一个IP的连接数量?
- pytorch_grad_cam——pytorch下的模型特征(Class Activation Mapping, CAM)可视化库
猜你喜欢

发现一款 JSON 可视化工具神器,太爱了!
![[micro service sentinel] degradation rules slow call proportion abnormal proportion abnormal constant](/img/4d/4d4424b609a3c0cd36c5c79daa8861.png)
[micro service sentinel] degradation rules slow call proportion abnormal proportion abnormal constant

Press key to control LED status reversal

Learn Tai Chi Maker - mqtt (VIII) esp8266 subscribe to mqtt topic

平均风向风速计算(单位矢量法)

Canvas particles: mouse following JS effect

Mmdetection valueerror: need at least one array to concatenate solution

达梦数据库安装

Dameng database installation
![[Shangshui Shuo series] day 6](/img/47/7cd44f4e361af53cac7cea9d0d7ecb.png)
[Shangshui Shuo series] day 6
随机推荐
mmdetection 用yolox训练自己的coco数据集
Yiwen teaches you Kali information collection
Flink学习4:flink技术栈
Oracle/PLSQL: NumToYMInterval Function
STM32入门介绍
Learn Tai Chi Maker - mqtt (VI) esp8266 releases mqtt message
Topolvm: kubernetes local persistence scheme based on LVM, capacity aware, dynamically create PV, and easily use local disk
CVPR2022 | PointDistiller:面向高效紧凑3D检测的结构化知识蒸馏
Getting started with Scala_ Immutable list and variable list
超级详细,2 万字详解,吃透 ES!
Yuantou firm offer weekly record 20220627
Oracle/PLSQL: Upper Function
人群模拟
Learning Tai Chi Maker - mqtt (VII) advanced mqtt theme
Google began to roll itself, AI architecture pathways was blessed, and 20billion generation models were launched
lottie. JS creative switch button animal head
栈溢出漏洞
C # check whether the date is in the correct format
Sample development of WiFi IOT Hongmeng development kit
Web development framework - Express (installation and use, static hosting, routing processing, use of Middleware)
https://github.com/ZouJiu1/PAT