zoukankan      html  css  js  c++  java
  • 【贪心】【HDOJ-1789】Doing Homework again

    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份作业要做,每份必须在一定时间内完成,否则扣分,求扣分最少的
    思路:按扣分的大小降序排序,然后将这份作业尽可能的安排的晚,如果无法安排,就扣分
    ***********************************************************************************************************************/
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <queue>
    #include <stack>
    #include <vector>
    using namespace std;
    typedef struct 
    {
        int d, r;
    }node;
    node a[1000+10];
    bool flag[1000+10];
    bool cmp(node a, node b)
    {
        return a.r > b.r;
    }
    int main()
    {
        freopen("data.in" , "r" , stdin);
        int t;
        scanf("%d", &t);
        while(t--)
        {
            int ans = 0;
            memset(flag , true , sizeof(flag));
            int n;
            scanf("%d", &n);
            for(int i = 0 ; i < n ; i ++)
                scanf("%d", &a[i].d);
            for(int i = 0 ; i < n ; i ++)
                scanf("%d", &a[i].r);
            sort(a , a + n , cmp);
            for(int i = 0 ; i < n ; i ++)
            {
                int mark = 0x7fffffff;
                for(int j = a[i].d ; j > 0 ; j --)
                {
                    if(flag[i])
                    {
                        flag[i] = false;
                        mark = -1;
                        break;
                    }
                }
                if(mark == 0x7fffffff)
                    ans += a[i].r;
            }
            printf("%d
    " , ans);
        }
        return 0;
    }
  • 相关阅读:
    [转载]单点登录SSO:概述与示例
    Go实现基于WebSocket的弹幕服务
    Redis事务涉及的watch、multi等命令
    PHP实现快速排序
    PHP实现单例模式
    PHP实现二分法查找
    PHP实现冒泡排序
    Mac包管理神器Homebrew
    Mac超快速搭建Nginx、PHP、PHPStorm、XDebug环境
    修改CentOS服务器时间为北京时间
  • 原文地址:https://www.cnblogs.com/ahu-shu/p/3560789.html
Copyright © 2011-2022 走看看