zoukankan      html  css  js  c++  java
  • hdu1789(贪心)

    Doing Homework again

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


    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
     思路:按照贪心的思想,每次做出最优决策,所以可以将作业按扣分高低排序,每次找到扣分最高的,将它安排进终止日期那一天,如果那天有事,就在往前推,,如果最后安排不下,就扣分。这样循环n次就可以了。
     1 #include <cstdio>
     2 #include <string.h>
     3 #include <algorithm>
     4 using namespace std;
     5 int T, N, hash[1010];
     6 struct HM
     7 {
     8     int day, score;
     9 } hm[1010];
    10 bool cmp (HM x, HM y )
    11 {
    12     if ( x.score != y.score )
    13         return x.score > y.score;
    14     return x.day > y.day;
    15 }
    16 int main ()
    17 {
    18     scanf ( "%d", &T );
    19     int i,j;
    20     while ( T -- )
    21     {
    22         scanf ( "%d", &N );
    23         int  sum = 0;
    24         for (i=1; i <= N; ++ i )
    25             scanf ( "%d", &hm[i].day );
    26         for (i=1; i <= N; ++ i )
    27             scanf ( "%d", &hm[i].score );
    28         sort ( hm+1, hm+N+1, cmp );
    29         memset ( hash, 0, sizeof ( hash ) );
    30         for (i=1; i<= N; ++i )
    31         {
    32             for ( j = hm[i].day; j > 0; j-- )
    33             {
    34                 if ( !hash[j] )
    35                 {
    36                     hash[j]=1;
    37                     break;
    38                 }
    39             }
    40             if ( !j )
    41                 sum += hm[i].score;
    42         }
    43         printf ( "%d
    ", sum );
    44     }
    45     return 0;
    46 }
    View Code
  • 相关阅读:
    27. Remove Element
    列表变成字典
    1. Two Sum
    CVPR2019:What and How Well You Performed? A Multitask Learning Approach to Action Quality Assessment
    959. Regions Cut By Slashes
    118. Pascal's Triangle
    loj3117 IOI2017 接线 wiring 题解
    题解 NOI2019 序列
    题解 省选联考2020 组合数问题
    题解 Educational Codeforces Round 90 (Rated for Div. 2) (CF1373)
  • 原文地址:https://www.cnblogs.com/lxm940130740/p/3914024.html
Copyright © 2011-2022 走看看