Problem Description
Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will reduce his score of the final test. And now we assume that doing everyone homework always takes one day. So Ignatius wants you to help him to arrange the order of doing homework to minimize the reduced score.
Input
The input contains several test cases. The first line of the input is a single integer T that is the number of test cases. T test cases follow.
Each test case start with a positive integer N(1<=N<=1000) which indicate the number of homework.. Then 2 lines follow. The first line contains N integers that indicate the deadlines of the subjects, and the next line contains N integers that indicate the reduced scores.
Each test case start with a positive integer N(1<=N<=1000) which indicate the number of homework.. Then 2 lines follow. The first line contains N integers that indicate the deadlines of the subjects, and the next line contains N integers that indicate the reduced scores.
Output
For each test case, you should output the smallest total reduced score, one line per test case.
题目大意:
你参加过ACM了,落下很多课程的作业,你需要去写作业,每天只能完成一门,完不成是要扣分的
给你每门作业的截止期限,然后给你对应要扣的分数,问你 最少扣多少分
题目思路:
当然是贪心了,我不晓得,这个贪心应该是最优解,但不知道为什么是总问题的最优解
先建立结构体,然后先对分数 进行排序,分数相同的话 然后对日期从小到大 因为日期短的话,就得先写,而且这个分数相同
然后建立一个标记数组,用来标记是否有时间来完成这项作业
之后对作业进行循环,对于第 i 份作业,前b[1..a[i].bed]是否有空余的一天把这个作业给完成 如果说完成不了的话,就只能
不做了
AC_CODE
#include<iostream>
#include<cstring>
#include<algorithm>
#define N 1005
using namespace std;
struct node
{
int ded;
int score;
}a[N];
int b[N]; //标记数组
int cmp(node a,node b)//分数不同的时候从高到低 分数相同的时候 日期从底到高
{
if(a.score==b.score)
return a.ded<b.ded;
return a.score>b.score;
}
int main()
{
int T;//测试个数
cin>>T;
int n;//作业的种类数
while(T--)
{
memset(b,0,sizeof(b));
int sum=0;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i].ded;
for(int i=1;i<=n;i++)
cin>>a[i].score;
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++)//循环作业种类
{
int j=a[i].ded; // 从截止时间开始往前推,如果有一天没用过,这一天就做这一门课,这门课不扣分
while(j)
{
if(!b[j])
{
b[j]=1;
break;
}
j--;
}
if(j==0)//如果j=0,表明从time往前的每一天都被占用了,这门课完不成
sum+=a[i].score;
}
cout<<sum<<endl;
}
return 0;
}