广告:
#include <stdio.h>
int main()
{
puts("转载请注明出处[vmurder]谢谢");
puts("网址:blog.csdn.net/vmurder/article/details/44499127");
}
题解:
写个结构体,重载一下小于号,然后扔优先队列里玩。
每次进来新的任务就把这段时间分给队列里的任务修改一下,然后把新的任务入队。
水题就瞎说点什么吧。
代码:
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 101000
using namespace std;
struct Eli
{
int d,t,x,a; // 编号 入坑时间 处理时间 优先度
bool read(){return (scanf("%d%d%d%d",&d,&t,&x,&a)!=EOF);}
Eli(int q=0,int r=0,int e=0,int w=0):d(q),t(r),x(e),a(w){}
bool operator < (const Eli &A)const{return a==A.a?t>A.t:a<A.a;}
}New,head;
priority_queue<Eli>pq;
int last,remain;
int main()
{
freopen("test.in","r",stdin);
while(New.read())
{
remain=New.t-last;
while(!pq.empty())
{
head=pq.top(),pq.pop();
if(head.x<=remain)
{
remain-=head.x;
last+=head.x;
printf("%d %d\n",head.d,last);
}
else {
head.x-=remain;
pq.push(head);
last+=remain;
remain=0;
break;
}
}
last+=remain;
pq.push(New);
}
while(!pq.empty())
{
head=pq.top(),pq.pop();
last+=head.x;
printf("%d %d\n",head.d,last);
}
return 0;
}
时间: 2024-10-13 03:30:42