码迷,mamicode.com
首页 > 其他好文 > 详细

Doing Homework again

时间:2015-11-05 11:59:40      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:

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. 
题意就是 一个hdu的神牛从world final英勇归来了。然后他要补作业。。
一共n个作业 完成每个作业都需要一天。但是每个作业有截止日期 如果超过了截止日期 就会扣分 
给出 n个作业的截止日期 和 如果超过截止日期要扣的分 现在要计算 怎么设计做作业的顺序扣分最少 计算出这个最少的扣分值
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.
SampleInput
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
SampleOutput
0
3
5
先按照扣分从大到小排序,分数相同则按照截止日期从小到大排序。。
 
然后按顺序,从截止日期开始往前找没有占用掉的时间。
如果找不到了,则加到罚分里面
 
技术分享
 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 using namespace std;
 5 
 6 const int MAXN=1010;
 7 
 8 struct Node
 9 {
10     int d,s;
11 }node[MAXN];
12 
13 bool used[10000];
14 
15 bool cmp(Node a,Node b)
16 {
17     if(a.s==b.s)
18     {
19         return a.d<b.d;
20     }    
21     return a.s>b.s;
22 }        
23 
24 int main()
25 {
26     int T;
27     int n;
28     int j;
29     scanf("%d",&T);
30     while(T--)
31     {
32         scanf("%d",&n);
33         for(int i=0;i<n;i++) scanf("%d",&node[i].d);
34         for(int i=0;i<n;i++) scanf("%d",&node[i].s);
35         sort(node,node+n,cmp);
36         memset(used,false,sizeof(used));
37         int ans=0;
38         for(int i=0;i<n;i++)
39         {
40             for(j=node[i].d;j>0;j--)
41             {
42                 if(!used[j])
43                 {
44                     used[j]=true;
45                     break;
46                 }    
47             }    
48             if(j==0)
49               ans+=node[i].s;
50         }    
51         printf("%d\n",ans);
52     }    
53     return 0;
54 }
View Code

 

Doing Homework again

标签:

原文地址:http://www.cnblogs.com/to-creat/p/4938963.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!