• 【贪心】【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;
    }
  • 相关阅读:
    Drawable、Bitmap、byte[]之间的转换
    关于java.lang.IllegalArgumentException: View not attached to window manager 错误的分析
    Android ListView使用BaseAdapter与ListView的优化
    Ubuntu, using svn from terminal
    Ubuntu 12.04(64位)上搭建android 开发环境 (ADT 、android-studio)
    Widget改变大小
    android4.0中实现AppWidget集合
    android 中 AppWidget 的 ListView 的实现
    解决IllegalStateException: Can not perform this action after onSaveInstanceState
    Drawable和Bitmap转换
  • 原文地址:https://www.cnblogs.com/ahu-shu/p/3560789.html
Copyright © 2020-2023  润新知