PAT (Advanced Level) 1026. Table Tennis (30)
情况比较多的模拟题。
交了50发的样子才AC......AC之后我的天空星星都亮了。
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
#include<vector>
using namespace std; struct X
{
int st,ml,len;
bool tag;
}s[+];
int n,m,k;
bool flag[+],g[+];
int ans[+],w[+];
queue<int>P,V; bool cmp(const X&a,const X&b) { return a.st<b.st; }
bool cmp2(const X&a,const X&b) { return a.ml<b.ml; } void init()
{
memset(ans,,sizeof ans);
memset(flag,,sizeof flag);
for(int i=;i<=;i++) w[i]=**;
} void read()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
int hh,mm,ss; scanf("%d:%d:%d",&hh,&mm,&ss);
s[i].st=hh*+mm*+ss;
scanf("%d",&s[i].len); s[i].len=min(*s[i].len,**);
cin>>s[i].tag;
}
scanf("%d%d",&m,&k);
for(int i=;i<=k;i++) {int id; cin>>id; flag[id]=;}
sort(s+,s++n,cmp);
s[].st=;
} void work()
{
int sz=,pre=; while()
{
if(sz==n) break;
int MIN=;
for(int i=;i<=m;i++) MIN=min(MIN,w[i]); for(int i=pre+;i<=n;i++)
{
if(s[i].st>MIN) break;
if(s[i].tag==) P.push(i); else V.push(i); pre=i;
} memset(g,,sizeof g);
for(int i=;i<=m;i++) if(w[i]==MIN) g[i]=; if(P.empty()&&V.empty())
{
sz++; pre++;int Find=;
if(s[pre].tag==)
{
for(int i=;i<=m;i++)
if(flag[i]==&&w[i]<=s[pre].st)
{
w[i]=s[pre].st+s[pre].len;
s[pre].ml=s[pre].st; Find=;
if(s[pre].ml<**) ans[i]++;
break;
}
if(Find==) continue;
for(int i=;i<=m;i++)
if(flag[i]==&&w[i]<=s[pre].st)
{
w[i]=s[pre].st+s[pre].len;
s[pre].ml=s[pre].st; Find=;
if(s[pre].ml<**) ans[i]++;
break;
}
}
else
{
for(int i=;i<=m;i++)
if(w[i]<=s[pre].st)
{
w[i]=s[pre].st+s[pre].len;
s[pre].ml=s[pre].st; Find=;
if(s[pre].ml<**) ans[i]++;
break;
}
}
continue;
} while(!V.empty())
{
int fail=,id=V.front();
for(int j=;j<=m;j++)
if(flag[j]&&g[j])
{
sz++;
s[id].ml=w[j];
w[j]=s[id].ml+s[id].len;
fail=; g[j]=; V.pop();
if(s[id].ml<**) ans[j]++;
break;
}
if(fail==) break;
} while()
{
int tmp1=,tmp2=,id;
if(P.empty()&&V.empty()) break;
if(!P.empty()) tmp1=P.front(); if(!V.empty()) tmp2=V.front();
if(s[tmp1].st<s[tmp2].st) id=tmp1; else id=tmp2; int fail=;
for(int j=;j<=m;j++)
if(g[j])
{
sz++;
s[id].ml=w[j];
w[j]=s[id].ml+s[id].len;
fail=; g[j]=; if(s[id].tag==) P.pop(); else V.pop();
if(s[id].ml<**) ans[j]++;
break;
}
if(fail==) break;
}
}
} void prin()
{
sort(s+,s++n,cmp2);
for(int i=;i<=n;i++)
{
if(s[i].ml>=**) continue; int fen=(s[i].ml-s[i].st+)/; printf("%02d:",s[i].st/); s[i].st=s[i].st-s[i].st/*;
printf("%02d:",s[i].st/); s[i].st=s[i].st-s[i].st/*;
printf("%02d ",s[i].st); printf("%02d:",s[i].ml/); s[i].ml=s[i].ml-s[i].ml/*;
printf("%02d:",s[i].ml/); s[i].ml=s[i].ml-s[i].ml/*;
printf("%02d ",s[i].ml); printf("%d\n",fen);
} for(int i=;i<=m;i++)
{
printf("%d",ans[i]);
if(i<m) printf(" ");
else printf("\n");
}
} int main()
{
init();
read();
work();
prin();
return ;
}
PAT (Advanced Level) 1026. Table Tennis (30)的更多相关文章
- Pat(Advanced Level)Practice--1026(Table Tennis)
Pat1026代码 题目描写叙述: A table tennis club has N tables available to the public. The tables are numbered ...
- 【PAT甲级】1026 Table Tennis (30 分)(结构体排序,trick较多)
题意: 输入一个正整数N(<=10000),表示客户(对)的大小,接着输入N行数据,每行包括一对顾客到场的时间,想要玩的时间,以及是否是VIP客户.接下来输入两个正整数K,M(K<=100 ...
- 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 (30)
A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...
- 1026. Table Tennis (30)
题目如下: A table tennis club has N tables available to the public. The tables are numbered from 1 to N. ...
- 1026 Table Tennis (30)(30 分)
A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...
- 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 ...
- 1026 Table Tennis (30分) 难度不高 + 逻辑复杂 +细节繁琐
题目 A table tennis club has N tables available to the public. The tables are numbered from 1 to N. Fo ...
- PAT (Advanced Level) 1111. Online Map (30)
预处理出最短路再进行暴力dfs求答案会比较好.直接dfs效率太低. #include<cstdio> #include<cstring> #include<cmath&g ...
随机推荐
- CentOS 7 时区设置
设置时区同样, 在 CentOS 7 中, 引入了一个叫 timedatectl 的设置设置程序. 用法很简单: # timedatectl # 查看系统时间方面的各种状态 $timedatectl ...
- java 数组变量与数组对象
数组是否必须初始化 对于这个问题,关键在于要弄清楚数组变量和数组对象的差别.数组变量是存放在栈内存中的,数组对象是存放在堆内存中的.数组变量只是一个引用变量,他能够指向实际的数组对象. 所谓的数组初始 ...
- shell 变量说明
变量说明 $$Shell本身的PID(ProcessID)$!Shell最后运行的后台Process的PID$?最后运行的命令的结束代码(返回值)$-使用Set命令设定的Flag一览$*所有参数列表. ...
- git repository 的使用
1. You should only be pushing to a bare repository. A bare repository is a repository that has no ch ...
- ignite中的消息使用实例
消息很简单,跟其他的mq相仿,关键点: 一,添加监听,订阅主题 二,发送消息 写了一个简单的示例: Receiver.java package test.ignite.broadcast; impor ...
- Dockerfile编写语法
docker镜像本质上就是一个个基础镜像的堆叠,为了做出我们想要的镜像,我们需要考虑最终镜像所需的所有基础环境,然后一层层堆叠.也就是不断以基础镜像搭建上层镜像. 先看例子: # Version: # ...
- IMP指针
可能大家一直看到有许多朋友在Runtime相关文章中介绍IMP指针的概念,那么IMP究竟有什么实际作用呢?让我们先从一个函数看起来. Method Swizzling 如果对Runtime有一定了解的 ...
- Photos FrameWork 续
1. Model PHAsset .PHAssetCollection.PHCollectionList 是Photos框架中的模型类,PHAsset类模型是图片或者视频文件数据:PHAssetCol ...
- public <T> void method(T var)
今天项目中遇到这样一个方法: public <T> void method(T var) 不太明白什么意思,后来搜索下几篇文章,自己总结一下,和大家分享. 先看例子: 1.static v ...
- Spark集群搭建中的问题
参照<Spark实战高手之路>学习的,书籍电子版在51CTO网站 资料链接 Hadoop下载[链接](http://archive.apache.org/dist/hadoop/core/ ...