杭电 1789 Doing Homework again (贪心 求最少扣分)

Description

zichen 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 zichen 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 zichen 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 
 1 #include<cstdio>
 2 #include<algorithm>
 3 using namespace std;
 4 struct stu
 5 {
 6     int d,s;
 7 }a[2000];
 8 bool cmp(stu a,stu b)
 9 {
10     if(a.s != b.s) return a.s>b.s;
11     else return a.d<b.d;
12 }
13 int main()
14 {
15
16     int t,n,j;
17     scanf("%d",&t);
18     while(t--)
19     {
20         int b[2000]={0,0};
21         int sum=0;
22         scanf("%d",&n);
23         for(int i = 0; i < n; i++)
24         {
25             scanf("%d",&a[i].d);
26         }
27             for(int i = 0; i < n; i++)
28             {
29                 scanf("%d",&a[i].s);
30             }
31                 sort(a,a+n,cmp);
32
33
34             /*    for(int i = 0;i < n;i++)
35                 printf("--%d--%d--\n",a[i].d,a[i].s);
36             */
37
38                 for(int i=0;i<n;i++)
39                 {
40                       for(j=a[i].d;j>0;j--)
41                       {
42                           if(b[j] == 0)
43                           {
44                               b[j]=1;
45                               break;
46                         }
47                       }
48                           if(j == 0) sum+=a[i].s;
49                 }
50                             printf("%d\n",sum);
51     }
52 }
时间: 2024-10-14 00:54:05

杭电 1789 Doing Homework again (贪心 求最少扣分)的相关文章

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 deadlin

Doing Homework again(杭电1789)

Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6833    Accepted Submission(s): 4070 Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he h

hdu 1789 Doing HomeWork Again (贪心算法)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 /*Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7903 Accepted Submission(s): 4680 Problem Description Ignatius has just c

HDU 1789 - Doing Homework again - [贪心+优先队列]

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem DescriptionIgnatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Eve

杭电 4883 TIANKENG’s restaurant (求饭店最少需要座椅)

Description TIANKENG manages a restaurant after graduating from ZCMU, and tens of thousands of customers come to have meal because of its delicious dishes. Today n groups of customers come to enjoy their meal, and there are Xi persons in the ith grou

HDUJ 1789 Doing Homework again 贪心

Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6335    Accepted Submission(s): 3746 Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he h

杭电1019 Least Common Multiple【求最小公倍数】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1019 解题思路:lcm(a,b)=a*b/gcd(a,b) 反思:最开始提交的时候WA,以为是溢出了,于是改成了long long,还是WA,于是就不明白了,于是就去看了discuss,发现应该这样来写 lcm(a,b)=a*gcd(a,b)*b;是为了以防a乘以b太大溢出,注意啊!!!!所以就先除再乘. #include<stdio.h> int gcd(int a,int b) { int t

hdu 1789 Doing Homework again(贪心)

题意:N个作业,每个作业有个deadline.每个作业完成耗时一天. 如果某个作业没在deadline前完成,则要扣去一定的分数. 给出N个要扣除的分数score[1]....score[N]. 如何安排使得扣分最少?求最少扣分. 思路: 按扣分多少从大到小排序,然后一个一个放到各自的deadline前的某个位置,哪个位置? 哪个位置有空就放那儿,且必须要都靠后!也就是从后往前放.这样可以保证最优地不占用更靠前的别人的deadline前的空间. 具体看代码,,,, 代码: struct node

HDU 5742 It&#39;s All In The Mind (贪心) 2016杭电多校联合第二场

题目:传送门. 题意:求题目中的公式的最大值,且满足题目中的三个条件. 题解:前两个数越大越好. #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; int gcd(int a,int b) { if(!b) return a; return gcd(b,a%b); } int main() { int t; ci