Doing homework again
来源:互联网 发布:泰森能打几个人知乎 编辑:程序博客网 时间:2024/05/13 22:28
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<algorithm>using namespace std;struct node{int day,cut;}work[1005];int cal[2010];bool cmp(node a,node b){if (a.cut != b.cut)return a.cut > b.cut;return a.day < b.day;}int main(){int t;scanf("%d",&t);while (t--){memset(cal,0,sizeof(cal));int n;scanf("%d",&n);for (int i = 0; i < n; ++i){scanf("%d",&work[i].day);}for (int i = 0; i < n; ++i){scanf("%d",&work[i].cut);}sort(work,work+n,cmp);int sign;int sum = 0;for (int i = 0; i < n; ++i){sign = work[i].day;while (sign--){if (!cal[sign]){cal[sign] = 1; //相同deadline 往前替补 deadline更大更无需担心break;}if (sign == 0)sum += work[i].cut;}}printf("%d\n",sum);}return 0;}
0 0
- HDU1789:Doing Homework again
- HDU1789--Doing Homework again
- Doing Homework again
- Doing Homework again(dp)
- hdu1789 Doing Homework again
- HDU Doing Homework again
- hdu Doing Homework again
- Doing Homework again
- 【1789 Doing Homework again】
- HDU1789 Doing Homework again
- Doing Homework again
- HDU1789 Doing Homework again
- Doing Homework again
- Doing Homework again 贪心
- Doing Homework again --贪心
- HDU Doing Homework again
- 【贪心】Doing Homework again
- Doing Homework again
- PAT甲级1087
- 面向对象三大特性之继承(二)
- 欢迎使用CSDN-markdown编辑器
- Python中的函数参数
- 【Python】学习笔记——-8、输入和输出
- Doing homework again
- scala操作符和关键字
- Python可变参数
- oracle的基本指令
- 对类的包装尝试
- Java面向对象(上)
- 实验吧 Zcrypt(ASIS CTF 2015) BY Assassin
- google的gflag的使用
- POI遍历Excle表