标签:des style io ar color os sp java for
3 2 1 4 2 08:00 1 5 09:00 2 1 2 5 4 3 08:00 1 4 08:01 2 2 08:02 2 2 2 5 4 2 08:00 1 1 08:04 1 1
08:02 09:01 08:05 08:10 08:10 08:05 08:10分析:普通模拟,卡了一天。代码示例:#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #define Max(a,b) a>b?a:b using namespace std; typedef struct { int time,id,num; }node; typedef struct { int time,s,t,id; }nodf; node E[2000+10]; int Time[2000+10]; int main() { int T,n,t,k,m; int a,b,c,d; scanf("%d",&T); while(T--) { scanf("%d%d%d%d",&n,&t,&k,&m); for(int i=0;i<m;i++) { scanf("%d:%d%d%d",&a,&b,&c,&d); E[i].time=a*60+b,E[i].id=c,E[i].num=d; Time[i]=-1; } nodf sum; sum.time=-1; for(int i=0;i<m;i++) { if(Time[i]!=-1) continue; sum.time=Max(sum.time,E[i].time); sum.s=sum.t=0,sum.id=E[i].id; while(sum.s<E[i].num) { sum.s+=k; sum.t+=t; } Time[i]=sum.time+sum.t; sum.time+=(sum.t-t),sum.s-=E[i].num; int j=i+1; while(E[j].time<=sum.time&&sum.s>0&&j<m) { if(E[j].num>sum.s&&E[j].id==sum.id) { E[j].num-=sum.s; sum.s=0; } if(E[j].num<=sum.s&&E[j].id==sum.id) { sum.s-=E[j].num; Time[j]=sum.time+t; } j++; } sum.time+=t; } for(int i=0;i<m;i++) { a=Time[i]/60,b=Time[i]%60; a%=24; printf("%02d:%02d\n",a,b); } if(T>0) printf("\n"); } return 0; }
hdu4884 TIANKENG’s rice shop【模拟】
标签:des style io ar color os sp java for
原文地址:http://blog.csdn.net/letterwuyu/article/details/41412905