zoukankan      html  css  js  c++  java
  • HDU1789时间贪心

    Doing Homework again

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 13883    Accepted Submission(s): 8053


    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
     想到了是贪心,但一直以为时间可能会给的很大不敢直接按时间一个一个遍历,没想到最后真的这样A的,恶心的题目为啥不说清数据范围!
    时间段是不会变化的,所以我们要充分利用好每一个时间段,即在这个时间段里让其获得最大的利益,由于彼此天数之间毫无关系所以可以贪心每一天。
    用一个数组记录这一天是否被使用,将结构体排序,排序方式:先按照分数大小排序,如果分数一样,天数大的排在前面;
    贪心方法:找出当前某门科目,从这门课的截止日期开始往前推只要遇到没标记的天就占用!
     
    为何倒着日期找:
    因为选择了一门科目后,对于后面的科目,截止日期可能在这个科目的截止日期的前面或者后面,后面的话没有影响,主要就是前面,如果这个科目占用了
    前面的某个位置有可能导致这个科目的截止日期的浪费和后面某个科目无法进行!是不符合贪心规则的。

    #include<bits/stdc++.h>
    using namespace std;
    int vis[10005];
    struct node
    {
    int a,b;
    }P[1005];
    bool cmp(node A,node B)
    {
    if(A.b==B.b) return A.a>B.a;
    else return A.b>B.b;
    }
    int main()
    {
    int t,n,m,i,j;
    cin>>t;
    while(t--){memset(vis,0,sizeof(vis));
    cin>>n;int ans=0,sumn=0;
    for(i=1;i<=n;++i) cin>>P[i].a;
    for(i=1;i<=n;++i) cin>>P[i].b,sumn+=P[i].b;
    sort(P+1,P+1+n,cmp);
    //for(i=1;i<=n;++i) cout<<P[i].a<<" "<<P[i].b<<endl;
    for(i=1;i<=n;++i){
    for(j=P[i].a;j>=1;j--){
    if(!vis[j]) {vis[j]=1;ans+=P[i].b;break;}
    }
    }//cout<<ans<<endl;
    cout<<sumn-ans<<endl;
    }
    return 0;
    }

  • 相关阅读:
    Oracle学习笔记:oracle的表空间管理和sqlserver的文件组对比
    Oracle学习笔记:一个特殊的ORA12541错误原因
    Oracle学习笔记:通过种子数据库设置dbid为指定值
    Oracle学习笔记:使用rman duplicate {to|for} 创建数据库
    Oracle学习笔记:利用rman数据库备份,手工创建clone数据库
    使用Cufon技术实现Web自定义字体
    分享七个非常有用的Android开发工具和工具包
    60佳灵感来自大自然的网页设计作品欣赏
    20个独一无二的图片滑动效果创意欣赏
    40个幻灯片效果在网页设计中的应用案例
  • 原文地址:https://www.cnblogs.com/zzqc/p/6789664.html
Copyright © 2011-2022 走看看