题目:​​http://acm.hdu.edu.cn/showproblem.php?pid=1789​

有t组测试数据,每组测试数据中有n门功课,第一排是完成它们的期限,第二排是未在限制的时间内完成的要扣除的分数,然后是需要求怎样安排才能使得扣的分数最少。

我是这样想的,从时间轴出发,尽量每天都安排有任务,假如某天有多个任务需要完成,就把未安排的score大的任务替换已安排的score小的任务,这样一直进行到最后一天。话说小小的思维漏洞真的很容易打击人的思考积极性啊,提交了两次WA后以为这种方法是错误的,后来发现计算reduced score有疏漏(开始认为被替换的任务的score之和就是解,其实有的任务根本就没push进去啊),重新改了便过了。另外按照score的大小降序排列也是不错的做法,针对每个任务让day从它的期限向前遍历到1,有空的一天就选中标记安排任务,如果不能就计入reduced score。

#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
struct node{
int day,score;
}work[1010];
bool cmp1(node a,node b){
return a.day<b.day;
}
struct cmp2{
bool operator()(node a,node b){
return a.score>b.score;
}
};
int main()
{
//freopen("cin.txt","r",stdin);
int t;
cin>>t;
while(t--){
int n,sum=0;
scanf("%d",&n);
memset(work,0,sizeof(work));
for(int i=0;i<n;i++){
scanf("%d",&work[i].day);
}
for(int i=0;i<n;i++){
scanf("%d",&work[i].score);
sum+=work[i].score;
}
sort(work,work+n,cmp1);
priority_queue<node,vector<node>,cmp2> que;
int day_t=1,i=0; //要用day_t(1---n)
while(day_t<=work[n-1].day){
if(work[i].day>day_t){
que.push(work[i++]);
}
if(work[i].day==day_t){
que.push(work[i++]);
while(work[i].day==day_t){
node tmp=que.top();
if(work[i].score>tmp.score){
que.pop();
que.push(work[i]);
}
i++;
}
}
day_t++;
}
while(!que.empty()){
node tmp=que.top();
sum-=tmp.score;
que.pop();
}
printf("%d\n",sum);
}
return 0;
}