HDU-1789 Doing Homework again
来源:互联网 发布:淘宝网址怎么修改 编辑:程序博客网 时间:2024/05/16 00:31
一道贪心题目,没感觉出来哪里是DP。
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<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;struct node{ int dead; int sc;};bool used[1010];node op[1010];int n;int t;bool cmp(node a,node b){ if(a.sc == b.sc) return a.dead < b.dead; return a.sc > b.sc;}int main(){ scanf("%d", &t); while(t--) { scanf("%d", &n); memset(op, 0, sizeof(op)); for(int i=1; i<=n; i++) { scanf("%d", &op[i].dead); } for(int i=1; i<=n; i++) { scanf("%d", &op[i].sc); } sort(op+1, op+n+1,cmp); int sum = 0; memset(used, false, sizeof(used)); for(int i=1; i<=n; i++) { int j; for(j=op[i].dead; j>=1; j--) // 倒着往前走,看看是否还有时间可以利用 { if(!used[j]) { used[j] = true; break; } } if(j<1) sum += op[i].sc; } cout << sum << endl; } return 0;}
水波。
阅读全文
0 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
- HotSpot的垃圾收集算法实现
- Boost】boost::noncopyable介绍
- C++通过bind,lambda表达式等实现简单的异步函数调用模型
- 百度Webuploader 大文件分片上传(.net接收)
- Android 图片处理总结
- HDU-1789 Doing Homework again
- 浅析python 中__name__ = '__main__' 的作用
- 43. Multiply Strings
- 浏览器兼容性问题
- 从零开始的RxJava2.0教程(一)基础
- AZure国外服务器访问速度
- 部署azkaban报错:Unrecognized SSL message, plaintext connection?
- Opencv目标跟踪—CamShift和meanshift算法
- 自定义log4j2配置文件地址