模拟之双队列HDU4884

本文介绍了一个比赛调度算法的实现细节,通过使用C++语言进行编程,该算法能够根据输入的比赛信息,包括开始时间、持续时间等,计算并输出比赛的具体时间安排。通过对已有资源的有效利用,确保了比赛能够顺利进行。
#include<iostream>
#include<cstdio>
#include<cstring> 
using namespace std;
const int N=1010;
const int lim=24*60;
int T,n,t,k,m;
int cnt[N],last[N];
void print(int time)
{
if(time>=lim) time%=lim;
printf("%02d:%02d\n",time/60,time%60);
}
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d %d %d %d",&n,&t,&k,&m);
memset(cnt,0,sizeof(cnt));
int hh,mm,a,b;
int cur=0;
for(int i=0;i<m;i++)
{
scanf("%d:%d %d %d",&hh,&mm,&a,&b);
hh=hh*60+mm;
if(cnt[a]>=b&&last[a]>=hh)
{
cnt[a]-=b;
print(last[a]+t);
continue;
}
if(cnt[a]&&last[a]>=hh)
b-=cnt[a];
int x=(b-1)/k+1;
cur=max(cur,hh)+t*x;
print(cur);
cnt[a]=x*k-b;
last[a]=cur-t;
}
if(T)  puts("");
}
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值