【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 ...
随机推荐
- php 加解密函数
PHP 加密解密函数: /** * 系统加密方法 * @param string $data 要加密的字符串 * @param string $key 加密密钥 * @param int $expir ...
- word写文档体会
1.找一个文档规范要求. 2.根据文档的规范要求调整正文的格式,标题1的格式,标题2的格式,标题3的格式,图表的格式,把没用的那些格式都删除掉. 3.图注表注后空格一行. 4.设置页眉页脚. 5.生成 ...
- 攻防世界 simple——js
simple_js [原理] javascript的代码审计 [目地] 掌握简单的javascript函数 [环境] windows [工具] firefox [步骤] 1.打开页面,查看源代码,可以 ...
- docker安装后启动报错
docker安装后启动不起来: 查看日志 /var/log/message 其中有一行为: Your kernel does not support cgroup memory limit ...
- yii2.0 构造函数
public function init() { parent:: init(); }
- 【HTML】输入密码访问
<script> (function(){ if('{{ page.password }}'){ if (prompt('请输入文章密码') !== '{{ page.password } ...
- pip install cv2 安装报错
pip install cv2 安装报错是一个常见现象: ERROR: Could not find a version that satisfies the requirement cv2 (fro ...
- php与js的false类型
php除了下面列出来的情况是false 其余情况都可以看成true 包括NaN 和 空资源 整数 0 浮点数 0.0 空字符串 '' 或者'0' false 空数组 NULL类型 空标生成Simpl ...
- C# DataTable去重,根据列名去重保留其他列
//去掉重复行 DataView dv = table.DefaultView; table = dv.ToTable(true, new string[] { "name", & ...
- Thymeleaf Tutorial 文档 中文翻译
原文档地址:https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html Thymeleaf官网地址:https://www.thym ...