1026. Table Tennis (30) @ PAT (Advanced Level) Practise

来源:互联网 发布:性价比高的水乳 知乎 编辑:程序博客网 时间:2024/06/05 15:19

附AC的链接

http://blog.csdn.net/ryvipa/article/details/8584282


26分,有2个case答案错误

#include<stdio.h>#include<vector>#include<queue>#include<algorithm>using namespace std;int N,K,M;int lfh,lfm,lfs;struct Table{int h,m,s;bool isVip;int count;bool operator <(const struct Table & tt) const{return (h==tt.h)?(m==tt.m?(s<tt.s):m<tt.m):h<tt.h;}};struct Player{int h,m,s;bool isVip;int last;bool operator <(const struct Player &  tp) const{return (h==tp.h)?(m==tp.m?s<tp.s:m<tp.m):h<tp.h;}bool operator <(const struct Table & tt) const{return (h==tt.h)?(m==tt.m?s<tt.s:m<tt.m):h<tt.h;}bool operator >(const struct Table & tt) const{return (h==tt.h)?(m==tt.m?s>tt.s:m>tt.m):h>tt.h;}};//priority_queue<Table> pqt;vector<Table> vt;vector<Player> vp;vector<Player>::iterator firstVip(){vector<Player>::iterator pit;for(pit=vp.begin();pit!=vp.end();pit++){if(pit->isVip){return pit;}}return pit;}bool inLine(Table & tt,vector<Player>::iterator tp){if(tp==vp.end())return false;elsereturn (tt.h==tp->h)?(tt.m==tp->m?tt.s>=tp->s:tt.m>tp->m):tt.h>tp->h;}vector<Table>::iterator firstAvailableVipTable(){Player tp=vp.front();vector<Table>::iterator tit;for(tit=vt.begin();tit!=vt.end();tit++){if(tit->isVip && tp>(*tit))break;}return tit;}vector<Table>::iterator minTable(){vector<Table>::iterator min=vt.begin();for(vector<Table>::iterator tit=vt.begin();tit!=vt.end();tit++){if((*tit)<(*min)){min=tit;}}return min;}int main(){scanf("%d",&N);struct Player tp;for(int i=0;i<N;i++){scanf("%d:%d:%d %d %d",&tp.h,&tp.m,&tp.s,&tp.last,&tp.isVip);if(tp.last>120)tp.last=120;vp.push_back(tp);}sort(vp.begin(),vp.end());scanf("%d %d",&K,&M);vt.resize(K);for(int i=0;i<K;i++){vt[i].count=0;vt[i].h=8;vt[i].m=0;vt[i].s=0;vt[i].isVip=false;}int tmp;for(int i=0;i<M;i++){scanf("%d",&tmp);vt[tmp-1].isVip=true;}vector<Player>::iterator pit;vector<Table>::iterator tt;while(!vp.empty()){tt=minTable();if(tt->h>=21)break;if(vp.front().isVip){vector<Table>::iterator tit;if((tit=firstAvailableVipTable())!=vt.end()){tt=tit;pit=vp.begin();int wait=60*(tt->h-pit->h)+(tt->m-pit->m)+(tt->s-pit->s)*1.0/60+0.5;printf("%02d:%02d:%02d %02d:%02d:%02d %d\n",pit->h,pit->m,pit->s,pit->h,pit->m,pit->s,0);tt->h+=(pit->m+pit->last)/60;tt->m=(pit->m+pit->last)%60;tt->s=pit->s;tt->count++;vp.erase(pit);continue;}}if(tt->isVip && inLine(*tt,pit=firstVip()))//table is for vip, and there are vip players in line{       int wait=60*(tt->h-pit->h)+(tt->m-pit->m)+(tt->s-pit->s)*1.0/60+0.5;printf("%02d:%02d:%02d %02d:%02d:%02d %d\n",pit->h,pit->m,pit->s,tt->h,tt->m,tt->s,wait);tt->h+=(tt->m+pit->last)/60;tt->m=(tt->m+pit->last)%60;vp.erase(pit);tt->count++;}else{pit=vp.begin();if((*pit)<(*tt) ||((*pit).h==tt->h && (*pit).m== tt->m && (*pit).s==tt->s))//there are players in line{int wait=60*(tt->h-pit->h)+(tt->m-pit->m)+(tt->s-pit->s)*1.0/60+0.5;printf("%02d:%02d:%02d %02d:%02d:%02d %d\n",pit->h,pit->m,pit->s,tt->h,tt->m,tt->s,wait);tt->h+=(tt->m+pit->last)/60;tt->m=(tt->m+pit->last)%60;vp.erase(pit);tt->count++;}else//there is no player in line{//printf("%d:%d:%d %d:%d:%d %d\n",pit->h,pit->m,pit->s,pit->h,pit->m,pit->s,0);tt->h=pit->h;tt->m=pit->m;tt->s=pit->s;}}}for(int i=0;i<vt.size()-1;i++){printf("%d ",vt[i].count);}printf("%d",vt[vt.size()-1].count);return 0;}


原创粉丝点击