T1
大意见链接。
先说自己在考场上的思路:
每个任务有结束时间的限制,这点特性很像codevs1052地鼠游戏
然后选择了将时间从后向前枚举,将当前时间所有可选择的任务丢进堆中,每次选择需要时间最小的一定最优(剩余给前面的时间更长)
对于当前可选择的最小任务时间如果无法再下一个时间点(实际的前一个的时间点)完成的话
将该任务进行的时间 -= 已进行的时间,重新扔进堆中
不断更新当前的时间last
自己的代码↓
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#define LL long long
using namespace std;
const LL MAXN = 200000 + 50;
struct zt
{
LL t,r;
}l[MAXN];
LL n;
bool cmp(zt a,zt b)
{
return a.r < b.r;
}
LL last;
long long cnt;
bool operator < (zt a,zt b)
{
return a.t > b.t;
}
priority_queue <zt> q;
LL p;
int main()
{
freopen("alma.in","r",stdin);
freopen("alma.out","w",stdout);
scanf("%lld",&n);
for(LL i = 1;i <= n;i ++)
{
scanf("%lld%lld",&l[i].t,&l[i].r);
}
sort(l + 1,l + n + 1,cmp);
last = l[n].r;
p = n - 1;
q.push(l[n]);
while(l[p].r == last && p)
{
q.push(l[p]);
p --;
}
while(p)
{
zt u = q.top();
q.pop();
while(last - u.t >= l[p].r)
{
last -= u.t;
cnt ++;
u = q.top();
q.pop();
if(q.empty())break;
}
if(last - u.t >= l[p].r){
cnt ++;
last = l[p].r;
}
else
{
u.t -= last - l[p].r;
q.push(u);
last = l[p].r;
}
while(l[p].r == last && p)
{
q.push(l[p]);
// if(l[p].r == 500 && l[p].t == 100)prLLf("haha\n");
p --;
}
}
while(last > 0 && !q.empty())
{
zt u = q.top();
q.pop();
cnt ++;
last -= u.t;
}
if(last < 0)cnt --;
printf("%lld",cnt);
fclose(stdin);
fclose(stdout);
return 0;
}
考场上没有将输入开成long long,被卡掉20分
然而不开long long在codevs上是可以过的……还是自家出题人太毒瘤QAQ
T2
T3
T4
见上一篇