当前位置:网站首页>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;
}边栏推荐
- Look! In June, 2022, the programming language ranking list was released! The first place is awesome
- How do I simplify the development of interfaces in open source systems?
- PAT甲级 1026 Table Tennis
- The use and introduction of pytorch 23 hook and the implementation of plug and play dropblock based on hook
- 解决cherry pick提交报错问题
- Web development framework - Express (installation and use, static hosting, routing processing, use of Middleware)
- I earned 3W yuan a month from my sideline: the industry you despise really makes money!
- Regular expressions: Syntax
- Oracle/PLSQL: To_ Clob Function
- jwt的认证流程和使用案例
猜你喜欢

ConstraintLayout(约束布局)开发指南

Why pass SPIF_ Sendchange flag systemparametersinfo will hang?

Cs5213 HDMI to VGA (with audio) single turn scheme, cs5213 HDMI to VGA (with audio) IC

【微服务|Sentinel】降级规则|慢调用比例|异常比例|异常数

Enterprise digital transformation: informatization and digitalization

three. JS domino JS special effect

学习太极创客 — MQTT(六)ESP8266 发布 MQTT 消息

栈溢出漏洞

PAT甲级 1023 Have Fun with Numbers
![[Shangshui Shuo series] day 6](/img/47/7cd44f4e361af53cac7cea9d0d7ecb.png)
[Shangshui Shuo series] day 6
随机推荐
Sample development of WiFi IOT Hongmeng development kit
Super detailed, 20000 word detailed explanation, thoroughly understand es!
lodash get js代码实现
Flink学习1:简介
YaLM 100B:来自俄罗斯Yandex的1000亿参数开源大模型,允许商业用途
Oracle/PLSQL: NumToYMInterval Function
Mmdetection uses yolox to train its own coco data set
XSS attack (note)
"All majors are persuading them to quit." is it actually the most friendly to college students?
Brief introduction of 228 dropout methods of pytorch and fast implementation of dropblock with 4 lines of code based on dropout
Parameter estimation -- Chapter 7 study report of probability theory and mathematical statistics (point estimation)
Laravel 的 ORM 缓存包
【一起上水硕系列】Day 6
What if asreml-r does not converge in operation?
C language -- Design of employee information management system
栈溢出漏洞
对数器
Flink學習2:應用場景
超級詳細,2 萬字詳解,吃透 ES!
Leetcode 785: judgment bipartite graph
https://github.com/ZouJiu1/PAT