zoukankan      html  css  js  c++  java
  • Doing Homework again

    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.InputThe 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.
    OutputFor 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

    非常体现贪心的思想,重点就是贪的策略和时间的转换,扣分高的优先完成,扣分相同而时间少的优先完成。然后看是否能在当前作业的deadline之前完成,而将时间从后向前检查,目的就是尽量在后面的天数
    完成当前作业。这点很重要!
     1 #include<cstdio> 
     2 #include<string>
     3 #include<cstring>
     4 #include<iostream>
     5 #include<algorithm>
     6 using namespace std;
     7 struct node{
     8     int time,grade;
     9     bool operator<(const node & i)const{
    10         if(grade==i.grade) return time<i.time;
    11         return grade>i.grade;
    12     }
    13 }cla[1005];
    14 
    15 int cases;
    16 int n;
    17 int vis[1005];
    18 
    19 int main()
    20 {   cin>>cases;
    21     while(cases--){
    22         cin>>n;
    23         for(int i=0;i<n;i++) scanf("%d",&cla[i].time);
    24         for(int i=0;i<n;i++) scanf("%d",&cla[i].grade);
    25         
    26         memset(vis,0,sizeof(vis));
    27         sort(cla,cla+n);
    28         int ans=0;
    29         for(int i=0;i<n;i++){
    30             int temp=cla[i].time;
    31             bool flag=false;
    32             while(temp){
    33                 if(!vis[temp]) {vis[temp]=true; flag=true; break; }
    34                 temp--; 
    35             }
    36             if(!flag) ans=ans+cla[i].grade;
    38         }
    39         cout<<ans<<endl;
    40     }
    41     return 0;
    42 }
  • 相关阅读:
    10 种保护 Spring Boot 应用的绝佳方法
    Redis 如何分析慢查询操作?
    Spring Boot 主类及目录结构介绍
    Redis 再牛逼,也得设置密码!!
    Spring Data Redis 详解及实战一文搞定
    Spring Boot Redis Cluster 实战干货
    超详细的 Redis Cluster 官方集群搭建指南
    Redis Linux 安装运行实战全记录
    hdu 4790 Just Random (思路+分类计算+数学)
    poj 1328 Radar Installation(贪心)
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/7274641.html
Copyright © 2011-2022 走看看