• hdu 1789 Doing Homework again 贪心


    Doing Homework again

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 20510    Accepted Submission(s): 11813


    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
    题意:给你完成每一个作业的截止日期,和每一个超过截至日期扣的分数,规定每天只能完成一项作业,要求完成所有作业使扣的总分数最小
     
    题解:按扣分从大到小排序,若扣分相同,截止日期小的排在前面;按排序后的顺序处理作业,从该作业的截至日期开始往前遍历,若还有某天未做作业(vis[i]==0),则该作业不计罚分
     
    #include<iostream>
    #include<algorithm>
    #include<string.h>
    #define ll long long 
    using namespace std;
    struct node
    {
        ll t;
        ll s;
    }p[1005];
    bool cmp(node a,node b)
    {
        if(a.s!=b.s)
            return a.s>b.s;
        else
            return a.t<b.t;
    }
    int vis[1005];
    int main()
    {
        int t,n;
        cin>>t;
        while(t--)
        {
            
            cin>>n;
            memset(vis,0,sizeof(vis));
            for(int i=1;i<=n;i++)
                cin>>p[i].t;
            
            for(int i=1;i<=n;i++)
                cin>>p[i].s;
            sort(p+1,p+1+n,cmp);
            ll ans=0;
            for(int i=1;i<=n;i++)
            {
                int flag=0;
                for(int j=p[i].t;j>=1;j--)
                {
                    if(vis[j]==0)
                    {
                        vis[j]=1;
                        flag=1;
                        break;
                    }
                }
                if(flag==0)
                    ans=ans+p[i].s;
            }
            cout<<ans<<endl;
    
        }
        return 0;
    
    }
  • 相关阅读:
    ubuntu set/unset proxy
    Caffe Ubuntu14.04 64位 的最快安装 (cuda7.5 + cudnn7.0 2016最新)
    OpenCV3.0.0+win10 64位+vs2015环境的下载,安装,配置
    Hadoop学习第一天
    PDF在xp或2003下正常在win7下乱码的问题
    android入门到熟练(五)---广播
    android入门到熟练(三)----UI界面
    android入门到熟练(二)----活动
    android入门到熟练(一)
    jQuery慢慢啃之回调(十三)
  • 原文地址:https://www.cnblogs.com/-citywall123/p/11184363.html
Copyright © 2020-2023  润新知