HDU 1789 Doing Homework again
来源:互联网 发布:地图龟淘宝哪家的好 编辑:程序博客网 时间:2024/06/16 17:49
Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 14870 Accepted Submission(s): 8679
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
333 3 310 5 131 3 16 2 371 4 6 4 2 4 33 2 1 7 6 5 4
Sample Output
035
题目大意:老师给了一个最后期限,每一个老师的作业有不同的分值,帮助Ignatius失去的分尽量的少
贪心水题。怎么贪呢?我们对所有的deadline从小到大排序,如果deadline相同,就让他们的分数从大到小排序
#include<iostream>#include<algorithm>using namespace std;struct Node{int deadline;int score;int flag;}homework[1010];bool cmp(Node a,Node b){if(a.deadline==b.deadline) return a.score>b.score;return a.deadline<b.deadline;}int main(){ios::sync_with_stdio(0);int n;cin>>n;while(n--){int num;cin>>num;for(int i=0;i<num;i++) cin>>homework[i].deadline;for(int i=0;i<num;i++){homework[i].flag=1;cin>>homework[i].score;}sort(homework,homework+num,cmp);int sum=0,day=1;for(int i=0;i<num;i++){if(homework[i].deadline>=day){day++;}else{int temp=homework[i].score,flag=i;for(int j=0;j<i;j++){if(homework[j].score<temp&&homework[j].flag){temp=homework[j].score;flag=j;}}sum+=temp;homework[flag].flag=0;}}cout<<sum<<endl;}}
阅读全文
1 0
- hdu 1789 doing homework again
- HDU 1789 Doing Homework again!
- hdu 1789 Doing Homework again
- hdu 1789 Doing Homework again
- hdu 1789 Doing Homework again
- hdu 1789 Doing Homework again
- Hdu 1789 - Doing Homework again
- HDU 1789 Doing Homework again
- hdu 1789 Doing Homework again
- HDU 1789 Doing Homework again
- hdu 1789 Doing Homework again
- hdu 1789 doing homework again
- HDU 1789 Doing Homework again
- HDU 1789 Doing Homework again
- HDU 1789 Doing Homework again
- HDU - 1789 Doing Homework again
- HDU 1789 Doing Homework again
- hdu 1789 Doing Homework again
- Extjs6.2 Form上传图片之前预览
- mysql新建用户在本地无法登录
- unity3d 一种实体动画序列帧的效果
- 利用sklearn进行tfidf计算
- 虚拟机垃圾回收相关知识整理(JVM GC)
- HDU 1789 Doing Homework again
- [深度学习]深度学习框架总结
- 没想到公司用的是xml方法进行数据交互
- 算法导论 所有结点最短路径问题 Johnson
- 使用阿里云搭建个人网站/服务器
- 设置debian的静态IP(方便简单)
- 3. S5PV210时钟体系结构框图了解
- activity跳转回退
- [ 学习 ] 8种方式帮助你如何从一名普通的程序员进阶成为一名伟大的程序员