题目:http://acm.hdu.edu.cn/showproblem.php?pid=1789
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.
3 3 3 3 3 10 5 1 3 1 3 1 6 2 3 7 1 4 6 4 2 4 3 3 2 1 7 6 5 4
0 3 5
题目是一个贪心问题,只要先排一下序,在用一个数组标记,从罚分大的开始,把对应课的最后一天标记为1,已经被标记的可以向前推,直到找到数组里面不为1的为止。如果没有找到,就表示该课程无法完成,就加入SUM中。这样基本就可以了吧!!
题目大意:先给定几门课程,每一门课需要一天的时间来完成。第一行为完成的最后时间,第二行是没有完成的罚分。求使罚分的最小的分数。
AC代码:
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
int a,b;
}q[1008]; //结构体表示,方便排序
bool cmp(node x,node y)
{
return x.b>y.b;
}
int main()
{
int t,n,i,sum,c;
int w[1008];
cin>>t;
while(t--)
{
sum=0;
memset(w,0,sizeof(w)); //标记数组初始化
cin>>n;
for(i=0;i<n;i++) cin>>q[i].a;
for(i=0;i<n;i++) cin>>q[i].b;
sort(q,q+n,cmp);
for(i=0;i<n;i++)
{
c=q[i].a;
while(w[c]!=0) //判断该标记点是否已使用
{
c--;
if(c==0)
{
sum+=q[i].b;break;
}
}
w[c]=1;
}
cout<<sum<<endl;
}
return 0;
}