zoukankan      html  css  js  c++  java
  • HDOJ 1789 Doing Homework again

    按惩罚由大到小排序,惩罚高的先完成,完成的时间尽量推后。

    Doing Homework again

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


    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
     
    Author
    lcy
     
    Source
     
    Recommend
    lcy
     
     1 #include <iostream>
     2 #include <cstring>
     3 #include <algorithm>
     4 
     5 using namespace std;
     6 
     7 struct k
     8 {
     9     int t;
    10     int p;
    11 }hw[1111];
    12 
    13 bool cmp(k a,k b)
    14 {
    15 if(a.p!=b.p)
    16     return a.p>b.p;
    17 else
    18     return a.t<b.t;
    19 }
    20 
    21 int main()
    22 {
    23     int T;
    24     cin>>T;
    25 while(T--)
    26 {
    27     memset(hw,0,sizeof(hw));
    28     int n;
    29     cin>>n;
    30     for(int i=0;i<n;i++)
    31         cin>>hw[i].t;
    32     for(int i=0;i<n;i++)
    33         cin>>hw[i].p;
    34 
    35     sort(hw,hw+n,cmp);
    36 
    37     int tp[10000];
    38     memset(tp,0,sizeof(tp));
    39 
    40     for(int i=0;i<n;i++)
    41     {
    42         for(int j=hw[i].t;j>=1;j--)
    43         {
    44             if(tp[j]==0)
    45                 {
    46                     tp[j]=1;
    47                     hw[i].p=0;
    48                     break;
    49                 }
    50         }
    51     }
    52 
    53     int ans=0;
    54     for(int i=0;i<n;i++)
    55         ans+=hw[i].p;
    56 
    57     cout<<ans<<endl;
    58 
    59 }
    60 
    61     return 0;
    62 }
  • 相关阅读:
    jQuery应用 代码片段
    正则表达式大全
    js表单编程
    补充回顾
    Socket网路编程
    异常处理
    day18-2 反射详解
    day18-1 面向对象进阶
    day18-1 多态
    day17-2 继承
  • 原文地址:https://www.cnblogs.com/CKboss/p/3113661.html
Copyright © 2011-2022 走看看