zoukankan      html  css  js  c++  java
  • HDU 1789 Doing Homework again(贪心)

    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
     
    Answer
    一开始输入数据组数N,然后输入每组数据的数据数n,即作业数,接下来两行,第一行表示每项作业的截止日期,第二行表示每项作业未完成的扣分,求最少扣的分是多少,每项作业耗时一天。先按照分数优先级1由大到小,日期优先级2由小到大,排序。然后从排序后的第一个作业开始,从这个作业的截止日期扫到第一天,如果有一天是空闲的,那么这一天做这个作业,如果没有空闲的,这个就交不了了(如果用前面的时间做这个作业,那么扣的分一定大于或等于这个作业不做扣的分,因为排序是分数从大到小排的)。循环结束后即可输出答案。
     
    #include <cstdio>
    #include <iostream>
    #include <string>
    #include <sstream>
    #include <cstring>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #include <map>
    #define PI acos(-1.0)
    #define ms(a) memset(a,0,sizeof(a))
    #define msp memset(mp,0,sizeof(mp))
    #define msv memset(vis,0,sizeof(vis))
    using namespace std;
    //#define LOCAL
    struct Node
    {
        int da;//日期
        int gd;//分数
    }t;
    bool date[1200];
    vector<Node> v;
    int cmp(Node n1,Node n2)
    {
        if(n1.gd!=n2.gd)return n1.gd>n2.gd;
        return n1.da<n2.da;
    }
    int main()
    {
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
    #endif // LOCAL
        ios::sync_with_stdio(false);
        int N;
        while(cin>>N)
        {
            while(N--)
            {
                int n;
                cin>>n;
                v.clear();
                ms(date);
                int ans=0;
                for(int i=0;i<n;i++)
                cin>>t.da,v.push_back(t);
                for(int i=0;i<n;i++)
                cin>>v[i].gd;
                sort(v.begin(),v.end(),cmp);
                for(int i=0,vsize=v.size();i<vsize;i++)
                {
                    t=v[i];
                    for(int j=t.da;j>=0;j--)
                    {
                        if(j==0){ans+=t.gd;break;}
                        if(date[j]==0){date[j]=1;break;}
                    }
                }
                printf("%d
    ",ans);
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    华为手机内核代码的编译及刷入教程【通过魔改华为P9 Android Kernel 对抗反调试机制】
    AndroidStudio升级到4.0之后,出现Warning: Default Activity not found解决办法
    Python解决gensim加载doc2vec或work2vec向量训练模型文件太慢甚至无法访问的情况
    layui 上传插件控制上传文件个数(换个角度思考问题)
    CDN访问异常重定向
    sql 语句优化
    swipper全屏垂直滚动获取高度问题
    tp6.0相对于tp5.1的变化
    项目打包文件ipa包瘦身
    load和initialize的区别
  • 原文地址:https://www.cnblogs.com/gpsx/p/5186751.html
Copyright © 2011-2022 走看看