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

    http://acm.hdu.edu.cn/showproblem.php?pid=1789

    Doing Homework again

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


    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
     
    View Code
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<stdlib.h>
     4 #define maxn 1010
     5 struct Node
     6 {
     7     int time;
     8     int score;
     9 }node[maxn];
    10 int flag[1010];
    11 int cmp(const void*x,const void*y)
    12 {
    13     struct Node *a=(Node*)x;
    14     struct Node *b=(Node*)y;
    15     return b->score-a->score;
    16 }
    17 int main()
    18 {
    19     int t,n;
    20     int m1,m2;
    21     scanf("%d",&t);
    22     while(t--)
    23     {
    24         m1=-1;
    25         m2=0;
    26         scanf("%d",&n);
    27         for(int i=0;i<n;i++)
    28         {
    29             scanf("%d",&node[i].time);
    30             if(m1<node[i].time)
    31             m1=node[i].time;
    32         }
    33         for(int i=0;i<n;i++)
    34         {
    35             
    36             scanf("%d",&node[i].score);
    37             m2+=node[i].score;
    38         }
    39         qsort(node,n,sizeof(node[0]),cmp);
    40         int sum=0;
    41         memset(flag,0,sizeof(flag));
    42         for(int i=0;i<n;i++)
    43         {
    44             
    45             for(int j=node[i].time;j>=1;j--)
    46             {
    47                 if(flag[j]==0)
    48                 {
    49                     //sum+=node[j].score;
    50                     flag[j]=1;
    51                     break;
    52                 }
    53                 if(j==1) sum+=node[i].score;
    54                 
    55             }
    56         }
    57         
    58         printf("%d\n",sum);
    59     }
    60 }
    Recommend
    lcy
  • 相关阅读:
    Python使用pymysql模块插入数据报错
    layui的select标签样式没有加载出来
    Python计算平均数
    Django获取小时内的数据
    mysql5.0忘记登录密码
    数据库介绍
    Linux基础
    测试理论
    计算机基础
    chrome 70 一下载文件就卡死
  • 原文地址:https://www.cnblogs.com/1114250779boke/p/2751156.html
Copyright © 2011-2022 走看看