HDU 1789 Doing Homework again
2016-07-23 15:01
603 查看
Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11349 Accepted Submission(s): 6670
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
题意:第一行输入t,第二行输入n(表示n个作业),第三行输入n个作业要完成的最低天数,第四行时n个作业的分数,求最少扣多少分
题解:贪心算法,以作业分数排序,分数相同时以完成时间排序,注意要记录在某天是否已经已经被占用
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11349 Accepted Submission(s): 6670
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
题意:第一行输入t,第二行输入n(表示n个作业),第三行输入n个作业要完成的最低天数,第四行时n个作业的分数,求最少扣多少分
题解:贪心算法,以作业分数排序,分数相同时以完成时间排序,注意要记录在某天是否已经已经被占用
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; #define LL long long #define M 1100 struct pro { int a, b; }; pro p[M]; bool cmp(pro x, pro y) { if(x.b == y.b) { x.a < y.a;//当作业量相同就先完成所需时间短的 } return x.b > y.b;//先按照作业分数从大到小排序 } bool ok[M]; int main() { int t; scanf("%d", &t); while(t--) { int n; scanf("%d", &n); int max = 0; for(int i=0; i<n; i++) { scanf("%d", &p[i].a); } for(int i=0; i<n; i++) { scanf("%d", &p[i].b); } sort(p, p+n, cmp); int ans = 0; memset(ok, false, sizeof(ok)); for(int i=0; i<n; i++) { int j; for(j=p[i].a; j>0; j--)//依次判断是否每一天都有需要完成的作业 { if(!ok[j]) { ok[j] = true; break; } } if(j == 0)//表示每天都已经被占 ans += p[i].b; } printf("%d\n", ans); } return 0; }
相关文章推荐
- ailed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test)
- POJ - 1995 Raising Modulo Numbers 【快速幂】
- hdu 5745 La Vie en rose(2016 Multi-University Training Contest 2——暴力)
- 2016 Multi-University Training Contest 1 1005 Necklace (hdu5727)【枚举+匹配】
- poj Raising Modulo Numbers 【快速幂 + 模取余】
- Contains Duplicate II
- 调用http://apistore.baidu.com网站的接口
- HDU5728 2016 Multi-University Training Contest 1 (递归+欧拉函数)
- http://blog.csdn.net/mindfloating/article/details/51534289
- UVA 11076-Add Again
- soft raid5阅读笔记之十四--resync和recovery的区别
- soft raid5阅读笔记之十三--异或操作
- soft raid5阅读笔记之十二--DMA相关
- 5. Longest Palindromic Substring && 214. Shortest Palindrome && 336. Palindrome Pairs
- soft raid5阅读笔记之十--状态标志
- soft raid5阅读笔记之九--MD中的superblock
- 373. Find K Pairs with Smallest Sums && 378. Kth Smallest Element in a Sorted Matrix
- soft raid5阅读笔记之七--MD中的bitmap
- maven install时报错Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile
- Contains Duplicate