当前位置:网站首页>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;
}边栏推荐
- [Shangshui Shuo series] day 6
- Flink Learning 2: Application Scenarios
- C # check whether the date is in the correct format
- Yiwen teaches you Kali information collection
- Paddlepaddle 21 is implemented based on dropout with 4 lines of code droplock
- three.js多米诺骨牌js特效
- Record the method of reading excel provided by unity and the solution to some pits encountered
- 超级详细,2 万字详解,吃透 ES!
- 达梦数据库的卸载
- Solve the problem of error reporting in cherry pick submission
猜你喜欢

Super detailed, 20000 word detailed explanation, thoroughly understand es!

Is the division of each capability domain of Dama, dcmm and other data management frameworks reasonable? Is there internal logic?

Yiwen teaches you Kali information collection

Window 加密壳实现

TopoLVM: 基于LVM的Kubernetes本地持久化方案,容量感知,动态创建PV,轻松使用本地磁盘

CVPR2022 | PointDistiller:面向高效紧凑3D检测的结构化知识蒸馏

Learn Tai Chi Maker - mqtt (VI) esp8266 releases mqtt message

Hot discussion: what are you doing for a meaningless job with a monthly salary of 18000?

Sample development of WiFi IOT Hongmeng development kit

Flink学习4:flink技术栈
随机推荐
Cvpr2022 | pointdistiller: structured knowledge distillation for efficient and compact 3D detection
Logarithm
Brief introduction of 228 dropout methods of pytorch and fast implementation of dropblock with 4 lines of code based on dropout
使用命令行安装达梦数据库
Learn Tai Chi Maker - mqtt (VI) esp8266 releases mqtt message
Flink学习5:工作原理
剑指Offer || :栈与队列(简单)
lodash get js代码实现
Test the respective roles of nohup and &
发现一款 JSON 可视化工具神器,太爱了!
pytorch_grad_cam——pytorch下的模型特征(Class Activation Mapping, CAM)可视化库
Quicksand painting simulator source code
谷歌开始卷自己,AI架构Pathways加持,推出200亿生成模型
three.js多米诺骨牌js特效
Microsoft365 developer request
DAMA、DCMM等数据管理框架各个能力域的划分是否合理?有内在逻辑吗?
Oracle/PLSQL: CharToRowid Function
学习太极创客 — MQTT(八)ESP8266订阅MQTT主题
mmdetection ValueError: need at least one array to concatenate解决方案
Memcached basics 11
https://github.com/ZouJiu1/PAT