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 ...
随机推荐
- Laravel中使用Redis
安装PHP PRedis PRedis是laravel访问redis的扩展包,只需要下载原码即可,不需要安装PHP扩展(如php-redis.so).但在这之前需要了解一个composer,因为lar ...
- nm applet disable
http://support.qacafe.com/knowledge-base/how-do-i-prevent-network-manager-from-controlling-an-interf ...
- sql server 的datediff函数
这两天要把一个sqlserver数据库的程序改成oracle的,发现两个数据库之间的函数很多不一样.sqlserver的数据库中的DateDiff 函数用法解释如下: 描述 返回两个日期之间的时间间隔 ...
- OpenGL—Android 开机动画源码分析一
.1 Android开机动画实现方式目前实现Android开机动画的方式主要是逐帧动画和OpenGL动画. ?逐帧动画 逐帧动画是一种常见的动画形式(Frame By Frame),其原理是在“连续的 ...
- JUST SORT
We define B is a Divisor of one number A if A is divisible by B. So, the divisors of 12 are 1, 2, 3, ...
- HDU 2102 A计划 经典搜索
A计划 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissio ...
- angular.js简介
angularJS是一个javaScript框架.可通过<script>标签添加到HTML页面 angular通过指令扩展了HTML,且通过表达式绑定数据到html 当网页加载完毕,Ang ...
- hdu_5719_Arrange(脑洞题)
题目连接:hdu_5719_Arrange 题意: 给你1-n这 n个数,设一个排列的第i个数为Ai, Bi为A1到Ai的最小值,Ci为C1到Ci的最大值,问你有多少种排列方式,然后输出取模后的答案 ...
- windows下,emacs的配置文件在哪儿?
配置文件_Emacs在你的家目录下"C:/Documents and Settings/username/Application Data". 在Window 7下,配置文件目录在 ...
- android zip解压缩
android zip解压缩 public class ZipUtils { public ZipUtils() { } /* 以输入流的形式解压 */ public static void UnZ ...