【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 ...
随机推荐
- springboot去除内嵌tomcat和打包在tomcat中运行需要做的步骤
去除内嵌tomcat和添加jsp依赖 去除内嵌tomcat 在springboot启动依赖中去除内嵌tomcat <dependency> <groupId>org.sprin ...
- java知识树
https://blog.csdn.net/aitaozi11/article/details/79652943 (学习Java的9张思维导图) 文章目录 针对技术栈学习 1. java基础 1.1 ...
- Bugku-CTF加密篇之+[]- (+++++ +++++ [->++ +++++ +++<] >++.+ +++++ .<+++ [->-- -<]>- -.+++ +++.< ++++[ ->.........)
+[]- +++++ +++++ [->++ +++++ +++<] >++.+ +++++ .<+++ [->-- -<]>- -.+++ +++.< ...
- html5异步单图片多图片上传两种实现方式 后台.net mvc接收
Asp.net mvc上传多张图片后台存储 前台页面通过<file name="img">标签数组上传图片,后台根据Request.Files["img&qu ...
- iOS 开发之 SDWebImage 底层实现原理分析
SDWebImage 是一个比较流行的用于网络图片缓存的第三方类库.这个类库提供了一个支持缓存的图片下载器.为了方便操作者调用,它提供了很多 UI 组件的类别,例如:UIImageView.UIBut ...
- family_to_level函数
#include <netinet/in.h> #include <sys/socket.h> int family_to_level(int family) { switch ...
- https://www.cnblogs.com/chanshuyi/p/alibaba_review_3_level.html
https://www.cnblogs.com/chanshuyi/p/alibaba_review_3_level.html http://www.cnblogs.com/skywang12345/ ...
- VMware15下载、安装、激活
1.VMware15下载 链接:https://pan.baidu.com/s/1bI8LReRY-5k81O3rrNgg-A 提取码:6c03 2.VMware15安装 3.VMware15激活
- Java入门笔记 03-面向对象(下)
介绍:除了前面介绍的关于类.对象的基本语法之外,下面继续介绍Java面向对象的特性. 一. 包装类: 从JDK 1.5以后,Java就提供了自动装箱和自动拆箱操作,即: 自动装箱:将一个基本类型的变量 ...
- PTA的Python练习题(十二)-第4章-6 输出前 n 个Fibonacci数
接下来应该做到 第4章-6 输出前 n 个Fibonacci数 了 def fib(n): a,b = 0,1 for i in range(n+1): a,b = b,a+b return a n= ...