Doing Homework again
程序员文章站
2022-04-01 20:34:59
...
Doing Homework again
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 3 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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.
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
先将分数从大到小排序,然后从当前截止日期往前推,看是否可以完成。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node{
int data, score;
}work[1010];
int a[1010];
int cmp(const node &a, const node &b){
return a.score > b.score;
}
int main(){
int t, n;
int date[1010], score[1010];
scanf("%d", &t);
while(t--){
scanf("%d", &n);
for(int i = 0; i < n; i++){
scanf("%d", &work[i].data);
}
for(int i = 0; i < n; i++){
scanf("%d", &work[i].score);
}
sort(work, work+n, cmp);
memset(a, 0, sizeof(a));
int sum = 0;
for(int i = 0; i < n; i++){
while(work[i].data--){
if(a[work[i].data+1] == 0){
//printf(" %d\n", work[i].data+1);
a[work[i].data+1] = 1;
break;
}
}
if(work[i].data == -1){
sum += work[i].score;
//printf("%d\n", sum);
}
}
printf("%d\n", sum);
}
return 0;
}
上一篇: JS的图片处理与合成详解
推荐阅读
-
1086 Tree Traversals Again (25 分)(二叉树的遍历)
-
(15 C++ Homework) Alipay System 1 user
-
HDU 1848 Fibonacci again and again(SG函数)
-
C语言动态规划_Doing Homework(HDU 1074)
-
Repeat Again
-
【STL队列和栈】HDU-1702 ACboy needs your help again!
-
HDU 1702 ACboy needs your help again!(栈和队列的简单应用)
-
Day1---Homework:设置接口,输入用户名、密码
-
Ubuntu20.04 SSH无法登陆root用户 Permission denied, please try again
-
Python Day4 homework - 列表,元组