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 ...
随机推荐
- Qt::ConnectionType(信号与槽的传递方式)
Qt::AutoConnection 自动连接:(默认值)如果信号在接收者所依附的线程内发射,则等同于直接连接.如果发射信号的线程和接受者所依附的线程不同,则等同于队列连接. Qt::DirectCo ...
- 笨方法学python--打印
1 print 语句 尾端的逗号 end1 = "C" end2 = "h" end3 = "e" end4 = "e" ...
- 产生一个int数组,长度为100,并向其中随机插入1-100,不重复
#define RANDOM(X) (rand() % X + 1) int main() { //标志数组 ] = {}; ] = {}; //默认的随机数种子是1,这样的话,每次执行这个程序都会得 ...
- 小蚂蚁搬家<贪心>
题意: 由于预知未来可能会下雨,所以小蚂蚁决定搬家.它需要将它的所有物品都搬到新家,新家的体积为V,小蚂蚁有N件物品需要搬,每件物品的体积为Ai,但他发现:每件物品需要新家剩余体积大于等于Bi才能使它 ...
- 以图搜图(一):Python实现dHash算法(转)
近期研究了一下以图搜图这个炫酷的东西.百度和谷歌都有提供以图搜图的功能,有兴趣可以找一下.当然,不是很深入.深入的话,得运用到深度学习这货.Python深度学习当然不在话下. 这个功能最核心的东西就是 ...
- 《CSS设计指南》阅读笔记
一.HTML实体 HTML实体常用于生成那些键盘上没有的印刷字符.以一个和号(&)开头,一个分号(:)结尾,二者之间是表示实体的字符串. 如:“左引号(") ”右引号(&qu ...
- 初探JavaScript魅力(二)
行为,样式,结构三者分离(javascript, css, html),不要在行间加行为,样式 样式优先级:*<标签<class<ID<行间 style与className,如 ...
- C#,js数据排序及其操作
List<int> listint=new List<int>{2,1,7,3,8,5,4,6};listint.Sort((x, y) => x - y); var a ...
- PL/SQL Developer StringBuffer 专用复制
;PL/SQL Developer SpecialCopy definition;<LINE_1> for first line;<LINE_*> for all other ...
- 高性能IO模型浅析(转)
转自:http://www.cnblogs.com/fanzhidongyzby/p/4098546.html 是我目前看到的解释IO模型最清晰的文章,当然啦,如果想要详细的进一步了解还是继续啃蓝宝书 ...