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;
    }
  • 相关阅读:
    10个值得我们关注的python博客
    Python获取并修改hosts
    详解python2 和 python3的区别
    Python监控网站运行状况
    用Flask实现视频数据流传输
    Python框架 Flask 项目实战教程
    使用Flask设计带认证token的RESTful API接口[翻译]
    使用python的Flask实现一个RESTful API服务器端[翻译]
    使用单用户模式破解Linux密码
    Linux软件的安装与卸载
  • 原文地址:https://www.cnblogs.com/ahu-shu/p/3560789.html
Copyright © 2011-2022 走看看