HDU-4884-TIANKENG’s rice shop
来源:互联网 发布:个人软件开发合同书 编辑:程序博客网 时间:2024/05/18 08:06
这个题算是一个模拟题,也不太难。我当时卡在了转换时间那,时间必须要处于0~24,0~60,我忘了那个取余操作。
代码:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int maxn=1100;struct Node{ int st; int id; int num; int ans; int nth; Node(){} Node(int sst,int sid,int snum) { st=sst; id=sid; num=snum; ans=-1; } bool operator < (const Node &a)const{ return st<a.st; }}a[maxn];int n,t,k,m,head[maxn],nxt[maxn];int main(){ int T; scanf("%d",&T); while(T--) { memset(head,-1,sizeof(head)); memset(nxt,-1,sizeof(nxt)); scanf("%d%d%d%d",&n,&t,&k,&m); for(int i=0;i<m;i++) { int h,d,id,num; scanf("%d:%d%d%d",&h,&d,&id,&num); a[i]=Node(h*60+d,id,num); } for(int i=0;i<m;i++) { if(head[a[i].id]==-1) head[a[i].id]=i; else { nxt[head[a[i].id]]=i; head[a[i].id]=i; } } int now=0; for(int i=0;i<m;i++) { if(a[i].num==0) { if(a[i].ans==-1) a[i].ans=now; continue; } now=max(now,a[i].st)+(a[i].num+k-1)/k*t; int res=k-(a[i].num%k==0?k:a[i].num%k),pos=i,last; a[i].ans=now; while(res&&nxt[pos]!=-1&&a[nxt[pos]].st<=now-t) { if(a[nxt[pos]].num==0) pos=nxt[pos]; else if(a[nxt[pos]].num<=res) { res-=a[nxt[pos]].num; a[nxt[pos]].num=0; a[nxt[pos]].ans=now; pos=nxt[pos]; } else { a[nxt[pos]].num-=res; res=0; break; } } } for(int i=0;i<m;i++) { a[i].ans%=24*60; printf("%02d:%02d\n",a[i].ans/60,a[i].ans%60); } if(T) printf("\n"); } return 0;}
0 0
- hdu 4884 TIANKENG’s rice shop(模拟)
- hdu 4884 TIANKENG’s rice shop(模拟)
- HDU-4884-TIANKENG’s rice shop
- HDU-4884-TIANKENG’s rice shop【模拟】
- hdu--4884--TIANKENG’s rice shop【模拟】
- HDU 4884 —— TIANKENG’s rice shop(模拟)
- [ACM] HDU 4884 TIANKENG’s rice shop (模拟)
- hdu 4884 TIANKENG’s rice shop && BestCoder Round #2 1002
- hdu 4884 TIANKENG’s rice shop(模拟)
- HDU 4884 TIANKENG’s rice shop (模拟)
- HDU TIANKENG’s rice shop(模拟)
- HDU4884 TIANKENG’s rice shop
- HDU 4884 Bestcoder#2-1002 TIANKENG’s rice shop【模拟一发】
- HDU 4884 TIANKENG’s rice shop(模拟)——BestCoder Round #2
- 【CUGBACM15级BC第二场 B】hdu 4884 TIANKENG’s rice shop
- hdu4884 TIANKENG’s rice shop【模拟】
- HDU4884 TIANKENG’s rice shop【模拟】
- hdu4884TIANKENG’s rice shop(模拟)
- Combo Box JavaFx with FXML
- 心胸与格局
- Struts2体系结构与基本流程
- Spark上矩阵运算库(四)基本API搭建完毕
- GCD SUM 强大的数论,容斥定理
- HDU-4884-TIANKENG’s rice shop
- 状态压缩DP习题集
- Combo Box JavaFx with FXML
- jobdu1046:求最大值
- [C#] 编程控制笔记本蓝牙与外部蓝牙设备通信
- Java设计模式之模板方法
- C++随机函数
- iOS MRC和ARC混编
- 【js练习】draggable属性和dataTransfer对象