hdu1789
来源:互联网 发布:锤子软件下载 编辑:程序博客网 时间:2024/06/05 14:12
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.
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.
333 3 310 5 131 3 16 2 371 4 6 4 2 4 33 2 1 7 6 5 4
035
/*很常规的贪心,很容易按照时间期限进行贪心,那样是不行的,我们要按照分数贪心,经分数从大到小排序,按照分数的顺序枚举每天的期限用掉一天就把当天标记,然后每次向前找如果找不到空着的一天那么就减分*/
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;struct node{ int time, score, id; bool operator < (const node &a) const{ if(score == a.score) return time < a.time; return score > a.score; }}nn[1000+10];int use[1000+10];int main(){ int t; scanf("%d", &t); while(t--){ memset(use, 0, sizeof(use)); use[0] = 1; int n; scanf("%d", &n); for(int i = 1; i <= n; i++){ scanf("%d", &nn[i].time); nn[i].id = 0; } for(int i = 1; i <= n; i++) scanf("%d", &nn[i].score); sort(nn + 1, nn+n+1); int sum = 0; for(int i = 1; i <= n; i++){ int flag = 0; for(int j = nn[i].time; j >= 1; j--){ if(!use[j]){ use[j] = 1; flag = 1; break; } } if(!flag) sum += nn[i].score; } printf("%d\n", sum); } return 0;}
0 0
- hdu1789
- hdu1789
- hdu1789
- HDU1789
- HDU1789
- HDU1789
- HDU1789
- hdu1789
- HDU1789 贪心
- hdu1789贪心
- HDU1789贪心
- HDU1789 贪心
- HDU1789贪心
- HDU1789 贪心
- HDU1789:Doing Homework again
- HDU1789--Doing Homework again
- hdu1789 t贪心
- hdu1789 Doing Homework again
- Clion安装配置教程 [C语言编程for Windows]
- jsp访问原理
- pyhton函数式编程函数map、reduce、filter、lambda
- Java语法糖(3):泛型
- 全面解析js中的数据类型与类型转换
- hdu1789
- 包装类小总结
- Java中堆和栈创建对象的区别
- 2017百度实习生招聘编程题
- Mybatis高级应用(下)
- GitHub 项目徽章的添加和设置
- Java中堆和栈创建对象的区别
- IM即时通讯实现原理
- Minimum Moves to Equal Array Elements II最小移动步数问题解法详解