zoukankan      html  css  js  c++  java
  • Hdu

    上题目

    Doing Homework again

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


    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
     
      题意就是有很多作业,每一个作业有一个最后上交的期限以及它的价值。求最后他有多少的价值没有得到。
      这一题是贪心,贪心的策略是先做价值最大的作业,在最后的期限那天做。
      题目说他最多只有1000份作业,但是上交期限没有说不大于1000,因此这里的做法是读入数据的时候如果上交的时间大于1000,那就把它改成1000。然后按作业的价值从大到小排序,如果价值相同,就按日前大到小排序。然后从数组的开头开始判断每一份作业,从它的期限之日开始向前扫描,如果遇到了还没有放的日子,就把作业放到这一天上,并标记好这一天已经有安排了。
        为什么这种策略可以行得通,我也不太懂为什么,因为不知道怎样证明,但是如果问我为什么要用这种做法的话,就是因为先把价值大,期限久的作业先安排好,然后下一个安排的必定是作业价值第二大的了,那当然是放在其期限的结束那一天,如果遇到两个价值期限都一样的的作业,那先做拿个都一样。
      大概是还没有完全搞懂贪心的思想,总觉得贪心这个名词用得不对。看来还要努力啊。  
     
  • 相关阅读:
    java.io.IOException: Premature EOF
    springmvc集成shiro例子
    eclipse调试(debug)的时候,出现Source not found,Edit Source Lookup Path,一闪而过
    【译】Core Java Questions and Answers【1-33】
    Spring bean依赖注入、bean的装配及相关注解
    【译】Spring 4 基于TaskScheduler实现定时任务(注解)
    【译】Spring 4 + Hibernate 4 + Mysql + Maven集成例子(注解 + XML)
    【译】Spring 4 @Profile注解示例
    【译】Spring 4 @PropertySource和@Value注解示例
    【译】Spring 4 自动装配、自动检测、组件扫描示例
  • 原文地址:https://www.cnblogs.com/sineatos/p/3203115.html
Copyright © 2011-2022 走看看