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 ...
随机推荐
- 初识mongo
进入mongo /usr/local/mongodb/bin/mongo --host 查看所有db show dbs 查看当前进入的db db 查看当前db的所有collection show co ...
- 还在纠结 Flux 或 Relay,或许 Redux 更适合你
重磅消息,Redux 1.0 发布,终于可以放心用于生产环境了! 在这个端应用技术膨胀的时代,每天都有一大堆框架冒出,号称解决了 XYZ 等一系列牛 X 的问题,然后过一段时间就不被提起了.但开发的应 ...
- myeclipse 调试JSP页面
http://jingyan.baidu.com/article/636f38bb1ef1aad6b9461048.html
- linux学习的哲学层面的思考-架构
参考:http://blog.chinaunix.net/uid-26119273-id-3356414.html 学习Linux,准备做产品的话,不要把Linux当成了终极目标(当然,这是对应用而言 ...
- 【多重背包模板】poj 1014
#include <iostream> #include <stdio.h> #include <cstring> #define INF 100000000 us ...
- ngnix配置文件
使用nginx最大的好处就是负载均衡. #设定负载均衡的服务器列表 upstream service{ server 10.4.29.174:7477; } server { ...
- Android中图片占用内存的计算
Android中图片占用内存的计算 原文链接 http://blog.sina.com.cn/s/blog_4e60b09d01016133.html 在Android开发中,我现在发现很多人还不 ...
- python顶级执行代码
只有主程序中由大量顶级执行代码(即没有被缩进的代码行),所有其他被导入的模块只应该又很少的顶级执行代码. 如果模块是被导入,__name__就是模块名. 如果模块是被直接执行,__name__就是__ ...
- Basically Speaking
Basically Speaking Time Limit: 2 Sec Memory Limit: 200 MB Submit: 19 Solved: 11 [Submit][Status][W ...
- C# 初步学习
这学期有了C#开发这门课....先做了计算器,还有进制转换,别人看来似乎很强,其实在ACM中算是两个简单的水题了.....参加竞赛一年下来,发现学到的算法和数据结构都是十分有用的东西. 计算器最核心的 ...