zoukankan      html  css  js  c++  java
  • 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 用shell脚本实现将当前文件夹下全部文件夹中的某一类文件复制到同一文件夹下
    读书笔记-2java虚拟机的可达性算法与finalize方法
    find the longest of the shortest (hdu 1595 SPFA+枚举)
    杭电 2176 取(m堆)石子游戏(博弈)
    MVC框架的优缺点
    Wireshark-TCP协议分析(包结构以及连接的建立和释放)
    Ubuntu安装教程--Win7系统中含100M保留分区
    eclipse新建android项目出现非常多错误
    关于简单的加密和解密算法
    在一台server上部署多个Tomcat
  • 原文地址:https://www.cnblogs.com/-citywall123/p/11184363.html
Copyright © 2011-2022 走看看