【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 ...
随机推荐
- java.util.Properties类,保存时保留注释及格式不变
原文地址:http://blog.csdn.net/benbenxiongyuan/article/details/53006097 参考地址:http://www.iteye.com/topic/1 ...
- red hat 报错:apt-get:找不到命令
Linux有两个系列:一个是RedHat系列,一个是Debian系列. RedHat系列:Redhat.Centos.Fedora等 Debian系列:Debian.Ubuntu等 RedHat 系列 ...
- 创建Maven project 提示pom.xml 首行错误
背景 使用eclipse创建Maven SpringBoot 2.2.0 项目时报错,更换springboot 版本也不行,排除框架依赖原因.然后别人的eclipse创建的同样2.2.2 maven项 ...
- PAT 1013 Battle Over Cities (dfs求连通分量)
It is vitally important to have all the cities connected by highways in a war. If a city is occupied ...
- VMware 14 激活密钥
VMware 14 激活密钥 FF31K-AHZD1-H8ETZ-8WWEZ-WUUVA CV7T2-6WY5Q-48EWP-ZXY7X-QGUWD
- Git远程推送和抓取分支
查看远程库信息 当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应起来了,并且,远程仓库的默认名称是origin.要查看远程库的信息,用git remote,或 ...
- 4500-X启动到“511K bytes of non-volatile configuration memory”,无法继续?
在设备做了某些配置后,尤其是升级,重启设备后,发现设备在如下界面卡住,无法进一步进入CLI命令行. Platform Manager: starting in standalone mode (act ...
- MYSQL数据库索引、事务。
=============================================================================================== inno ...
- hadoop学习笔记(二):hdfs优点和缺点
优点 其中的10k+,指的是每一个块必须>=1M 缺点 低延迟:是指hadoop处理数据都是以分钟为单位的,而不像storm那样的是以毫秒级为单位的. 高吞吐率:是指你分布式存储的文件块的大小必 ...
- 强化学习-Q-learning学习笔记
Q学习动作探索策略中的ep-greepy,以ep的概率进行随机探索,以1-ep的概率以最大值策略进行开发,因为设定的迭代次数比较多,所以肯定存在一定的次数去搜索不同的动作. 1)Python版本 b站 ...