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 ...
随机推荐
- php---数组序列化
有两种选择:serialize,json_encode. 需求:对数组进行序列化后保存在文件中,以便爬虫来抓取文件.并且序列化后的字符串只有一行,不希望在该字符串中出现换行,即使数组中某个元素中有换行 ...
- windows下使用git管理github项目
1. 下载安装msysgithttp://code.google.com/p/msysgit/downloads/list2. 注册github账号3. 生成ssh公钥和私钥ssh-keygen -C ...
- Eclipse如何自定义format代码
- Goods transportation
Goods transportation time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Tree Restoring
Tree Restoring Time limit : 2sec / Memory limit : 256MB Score : 700 points Problem Statement Aoki lo ...
- LightOJ 1341 Aladdin and the Flying Carpet 算数基本定理
题目大意:给出面积n,和最短边m,求能形成的矩形的个数(不能为正方形). 题目思路:根据算数基本定理有: 1.每个数n都能被分解为:n=p1^a1*p2^a2*^p3^a3……pn^an(p为素数); ...
- 美团,点评,澎湃等APP的启示
事先声明,因个人能力尚浅,文章若有不足之处,望留言指出,也欢迎成为好朋友. 本来想打算写团购类APP的竞品分析,但是发现不管是天天果园这样生鲜APP,还是澎湃这样的新闻资讯APP,思路差不多,都是: ...
- php cookies自动登录
<?php header('Content-type: text/html; charset=utf-8'); error_reporting(0); //自动登陆 if($_COOKIE[&q ...
- android执行外部命令、检测文件是否存在、自动检测U盘路径
private final String UDiskFileName = "/2969_logo/bootfile.image"; private final String Loc ...
- java 数据流
Example10_11.java import java.io.*; public class Example10_11 { public static void main(String args[ ...