【PAT甲级】1026 Table Tennis (30 分)(结构体排序,trick较多)
题意:
输入一个正整数N(<=10000),表示客户(对)的大小,接着输入N行数据,每行包括一对顾客到场的时间,想要玩的时间,以及是否是VIP客户。接下来输入两个正整数K,M(K<=100,M<=K),表示球桌的数量和其中VIP球桌的数量,接下来输入一行M个正整数,表示VIP球桌的编号。依照每对客户开始打球的时间由小到大顺序输出N行:他们的到场时间和开始打球的时间以及四舍五入输入等待时长,最后一行输出每张球桌服务的客户对数。如果客户21点前没有得到服务,则不输出他们的数据。
trick:
第8组数据包含需要对分钟进行四舍五入的数据,一开始没用翻译采取直接上取整发现这个点过不去。
第3组数据包含恰好21点到达的客户,他们是不可以接受服务的,这个点找了较长时间才发现。
第7组数据包含VIP客户需要先安排到VIP球桌的数据且VIP球桌不空闲的数据。
第5组数据包含VIP客户需要安排到VIP球桌且VIP球桌空闲的数据。
第1,2组数据包含当前无球桌空闲的数据。
第4,6组数据包含当前无VIP客户的数据。
第0组数据即为样例。
(对于数据的揣测基于我提交代码的不同,可能有误,仅希望有缘人可以借此少走弯路)
对于题干最后一句话:
On the other hand, if when it is the turn of a VIP pair, yet no VIP table is available, they can be assigned as any ordinary players.
On the other hand在Codeforces网站上的常用意为换句话说,意思是On the other hand后面的话和上一句话表达的意思是一样的只是换了种说法,这道题中On the other hand的意思应该是另一方面,因为我经常打Codeforces所以刚做题时我习惯地忽略了On the other hand后面的话,这道题的题意确实使这道题蒙上了一些细节方面的理解薄雾。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int table[];
int tt[];
int tans[];
int vipid[];
typedef struct customers{
string s;
int t,pt,ft,flg;
};
customers c[];
typedef struct ans{
string s;
int t,st;
};
ans a[];
bool cmp(customers a,customers b){
return a.t<b.t;
}
bool cmp2(ans a,ans b){
return a.st<b.st;
}
char anss[][];
int main(){
int n;
cin>>n;
for(int i=;i<=n;++i){
cin>>c[i].s>>c[i].pt>>c[i].flg;
if(c[i].pt>=)
c[i].pt=;
c[i].pt*=;
c[i].t=(c[i].s[]-'')*+(c[i].s[]-'')*+(c[i].s[]-'')*+(c[i].s[]-'')*+(c[i].s[]-'')*+c[i].s[]-'';
}
int sum,vip;
cin>>sum>>vip;
int x;
for(int i=;i<=vip;++i){
cin>>x;
table[x]=;
}
sort(c+,c++n,cmp);
int cnt=;
for(int i=;i<=n;++i)
if(c[i].flg)
vipid[++cnt]=i;
int sew=,mn=1e9,pos=;
int cntt=;
for(int i=;i<=n;++i){
if(a[i].t)
continue;
if(c[i].t>=*)
break;
sew=,mn=1e9,pos=;
if(c[i].flg==){
for(int j=;j<=sum;++j){
if(!table[j])
continue;
if(tt[j]<=c[i].t){
tt[j]=c[i].t+c[i].pt;
a[i].s=c[i].s;
a[i].t=c[i].t;
a[i].st=c[i].t;
++tans[j];
sew=;
break;
}
if(tt[j]<mn){
mn=tt[j];
pos=j;
}
}
if(sew)
continue;
for(int j=;j<=sum;++j){
if(tt[j]<=c[i].t){
tt[j]=c[i].t+c[i].pt;
a[i].s=c[i].s;
a[i].t=c[i].t;
a[i].st=c[i].t;
++tans[j];
sew=;
break;
}
if(tt[j]<mn){
mn=tt[j];
pos=j;
}
}
if(sew)
continue;
if(tt[pos]<*){
a[i].st=tt[pos];
tt[pos]+=c[i].pt;
a[i].s=c[i].s;
a[i].t=c[i].t;
++tans[pos];
}
continue;
}
sew=,mn=1e9,pos=;
for(int j=;j<=sum;++j){
if(tt[j]<=c[i].t){
tt[j]=c[i].t+c[i].pt;
a[i].s=c[i].s;
a[i].t=c[i].t;
a[i].st=c[i].t;
++tans[j];
sew=;
break;
}
if(tt[j]<mn){
mn=tt[j];
pos=j;
}
}
if(sew)
continue;
if(table[pos]&&tt[pos]<*){
while(a[vipid[cntt]].t)
++cntt;
if(cntt<=cnt&&c[vipid[cntt]].t<=tt[pos]){
a[vipid[cntt]].st=tt[pos];
tt[pos]+=c[vipid[cntt]].pt;
a[vipid[cntt]].s=c[vipid[cntt]].s;
a[vipid[cntt]].t=c[vipid[cntt]].t;
--i;
++tans[pos];
++cntt;
}
else{
a[i].st=tt[pos];
tt[pos]+=c[i].pt;
a[i].s=c[i].s;
a[i].t=c[i].t;
++tans[pos];
}
}
else if(tt[pos]<*){
a[i].st=tt[pos];
tt[pos]+=c[i].pt;
a[i].s=c[i].s;
a[i].t=c[i].t;
++tans[pos];
}
}
sort(a+,a++n,cmp2);
for(int i=;i<=n;++i){
if(!a[i].t)
continue;
cout<<a[i].s<<" ";
int temp=a[i].st;
anss[i][]=a[i].st/+'';
a[i].st%=;
anss[i][]=a[i].st/+'';
a[i].st%=;
anss[i][]=':';
anss[i][]=a[i].st/+'';
a[i].st%=;
anss[i][]=a[i].st/+'';
a[i].st%=;
anss[i][]=':';
anss[i][]=a[i].st/+'';
a[i].st%=;
anss[i][]=a[i].st+'';
cout<<anss[i]<<" ";
int x=(temp-a[i].t)/;
if((temp-a[i].t)%>=)
++x;
cout<<x<<"\n";
}
for(int i=;i<=sum;++i)
cout<<tans[i]<<((i==sum)?"":" ");
return ;
}
【PAT甲级】1026 Table Tennis (30 分)(结构体排序,trick较多)的更多相关文章
- PAT 甲级 1026 Table Tennis (30 分)(坑点很多,逻辑较复杂,做了1天)
1026 Table Tennis (30 分) A table tennis club has N tables available to the public. The tables are ...
- PAT甲级1026. Table Tennis
PAT甲级1026. Table Tennis 题意: 乒乓球俱乐部有N张桌子供公众使用.表的编号从1到N.对于任何一对玩家,如果有一些表在到达时打开,它们将被分配给具有最小数字的可用表.如果所有的表 ...
- PAT 甲级 1026 Table Tennis(模拟)
1026. Table Tennis (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A table ...
- 1026 Table Tennis (30分) 难度不高 + 逻辑复杂 +细节繁琐
题目 A table tennis club has N tables available to the public. The tables are numbered from 1 to N. Fo ...
- 1026 Table Tennis (30分)
A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...
- PAT甲级1026 Table Tennis【模拟好题】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805472333250560 题意: 有k张乒乓球桌,有的是vip桌 ...
- PAT A 1022. Digital Library (30)【结构体排序检索】
https://www.patest.cn/contests/pat-a-practise/1022 直接模拟, 输入,按id排序,检索 #include <iostream> #incl ...
- PAT 甲级 1028. List Sorting (25) 【结构体排序】
题目链接 https://www.patest.cn/contests/pat-a-practise/1028 思路 就按照 它的三种方式 设计 comp 函数 然后快排就好了 但是 如果用 c++ ...
- PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)
1080 Graduate Admission (30 分) It is said that in 2011, there are about 100 graduate schools ready ...
随机推荐
- react脚手架和深入理解jsx语法
react的mvc和vue的mvvm vue的mvvm属于双向绑定,view层,model数据层,vm实现双向绑定的控制层 此种模式,再某一类项目种很有优势:管理系统 ( OA, ERP , CRM ...
- Spark原理概述
原文来自我的个人网站:http://www.itrensheng.com/archives/Spark_basic_knowledge 一. Spark出现的背景 在Spark出现之前,大数据计算引擎 ...
- MySQL:ALTER COLUMN、MODIFY COLUMN 和 CHANGE COLUMN
ALTER COLUMN.MODIFY COLUMN 和 CHANGE COLUMN 语句修改列: ALTER COLUMN:改变.删除列的默认值(备注:列的默认值存储在 .frm 文件中). 这个语 ...
- MyBatis逆向工程的使用(非插件方式)
一.概述 MyBatis是目前流行的优秀持久层框架,其逆向工程更是大大缩减了开发时间.所谓逆向工程,指的是mybatis根据数据库设计好的表,自动生成对应model.mapper及mapper.xml ...
- python正则表达式中括号的作用,形如 "(\w+)\s+\w+"
先看一个例子: import re string="abcdefg acbdgef abcdgfe cadbgfe" #带括号与不带括号的区别 regex=re.compile(& ...
- Ubuntu python3 与 python2 的 pip调用
ubuntu 是默认装有pytthon2.x 与 python3.x 共存的 通常终端里 python 表示 python2 版本 python3 表示 python3 版本 (如果你没更改软链接设置 ...
- 三 模拟实现顺序表ArrayList
/** * 顺序表,重点是数组动态扩容,插入 * 底层采用数组,长度可以动态变化,此处采用增长一倍 * java.util.ArrayList每次增长50% * int newCapacity = ...
- layer.open({}) 子页面传参并调用父页面的方法
闲话少说先看效果!!! 说明适用场景:在a.jsp页面,点击查看一个文件,layer.open弹出b.jsp页面,在b.jsp页面可以修改文件的名称(其实是去改了数据库),但是关闭弹窗的后,要求不刷新 ...
- Educational Codeforces Round 80 C. Two Arrays(组合数快速取模)
You are given two integers nn and mm . Calculate the number of pairs of arrays (a,b)(a,b) such that: ...
- SSD算法
SSD算法 2016 出的目标检测算法 SSD效果主要有三点: 1.多尺度 2.设置了多种宽高比的(anchor box)default box 3.数据增强 1.1 设置 default box ...