hdu 1789 doing homework

Doing Homework again

Time Limit: 1000/1000 MS (Java/Others)    

Memory Limit: 32768/32768 K (Java/Others)

 

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.
 Output
For each test case, you should output the smallest total reduced score, one line per test case.
 
Sample Input
  
  
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
 
Sample Output
 
 
0 3 5
 
题意:就是要交作业的,第一行是测试组数,下面是有几项作业,再往下的一行是交作业的日期,再往下是作业的分值, 规则是在规定时间交不上作业的话,要扣分,(而且一项作业的完成时间是一天)那么给出数据之后,怎么安排作业 的计划能使得扣分最少! #include<stdio.h> #include<algorithm> using namespace std; struct mb{     int time,fenshu;     bool flag;         //做个标记 }s[1001]; int cmp(mb a,mb b) {     if(a.time!=b.time)   //如果时间不一样的话,那么时间小的在前面     return a.time<b.time;     return a.fenshu>b.fenshu; //如果时间一样的话,就让分数大的在前面 } int main() {     int N;     scanf("%d",&N);     while(N--)     {         int t,i,j;         scanf("%d",&t);         for(i=0;i<t;i++)         {             scanf("%d",&s[i].time);         }         for(i=0;i<t;i++)         {             scanf("%d",&s[i].fenshu);             s[i].flag=true;         //布尔变量,只有真或假         }         sort(s,s+t,cmp);                  int sum=0,k=1;          //因为时间的最小值是第一天         for(i=0;i<t;i++)         {             if(s[i].time>=k)     //如果时间是大于或时间,说明能在k时间之前交上作业,不扣分             {                 k++;             //如果可以交上作业,则表示不扣分,直接K++,然后比较下一个                 continue;        //并且,可以交上作业的话,不用表示 if 语句下面的扣分条件,直接再次循环             }             //下面是时间在K之前,说明不能按时完成,那么这时候就要考虑将这个时间之前的可以完成的             //分数最少的作业跟此作业交换,先写扣分多的,不写扣分最少的             int min=s[i].fenshu,u=i; //u=i,不能省略,因为,如果找不到比这个分值小的作业的 //话,那么就不进下面的for循环,不做交换,直接扣分             for(j=0;j<i;j++)             {                 if(min>s[j].fenshu && s[j].flag)    //寻找在i之前扣分最少的作业,直接被扣,让sum加上扣分的分数                 {                 min=s[j].fenshu;                    u=j;                 }             }             sum=sum+s[u].fenshu;             s[u].flag=false;              //当这个数据操作过一次之后,就不能再次操作了, //因为原来这个位置的扣分数就是最小的         }         printf("%d\n",sum);     }     return 0; } 这篇博客是在看完大神的博客之后写的,但这个步骤分析比较详细,适合我这种渣渣,然后 做完这道题之后,我感觉这种解法很周密,巧妙,详细,本人感觉相当于一道nyoj上难度为3的题, 值得一做!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值