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;
    }
  • 相关阅读:
    一个微信小程序跳转到另一个微信小程序
    微信小程序 canIUse
    微信小程序 点击事件 传递参数
    jquery 在将对象作为参数传递的时候要转换成 JSON
    微擎后台进行GET提交
    微信小程序添加底部导航栏
    jquery 中 html与text函数的区别
    C++ int与char[]的相互转换
    Qt error: LNK1158 无法运行rc.exe解决办法
    Qt error C3615: constexpr 函数 "qCountLeadingZeroBits" 不会生成常数表达式
  • 原文地址:https://www.cnblogs.com/ahu-shu/p/3560789.html
Copyright © 2011-2022 走看看