题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789

/*Doing Homework again

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7903 Accepted Submission(s): 4680 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. 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 Author
lcy Source
2007省赛集训队练习赛(10)_以此感谢DOOMIII */
//贪心算法
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = + ;
struct Node{
int d, s;
};
Node node[maxn];
int Mark[maxn];
bool cmp(Node a, Node b){
return a.s > b.s;
}
int main()
{
int t, n;
while(~scanf("%d", &t)){
while(t--){
scanf("%d", &n);
memset(Mark, , sizeof(Mark));
for(int i = ; i <= n; i++) scanf("%d", &node[i].d);
for(int i = ; i <= n; i++) scanf("%d", &node[i].s);
sort(node+, node+n+, cmp);
int i, j, cnt = ;
for(i = ; i <= n; i++){
for(j = node[i].d; j >= ; j--){
if(!Mark[j]){
Mark[j] = ;
break;
}
}
if(j == ) cnt += node[i].s;
}
printf("%d\n", cnt);
}
}
return ;
}

hdu 1789 Doing HomeWork Again (贪心算法)的更多相关文章

  1. HDU 1789 - Doing Homework again - [贪心+优先队列]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...

  2. HDU 1789 Doing Homework again(贪心)

    Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...

  3. hdu 1789 Doing Homework again (Greedy)

    Problem - 1789 继续贪心.经典贪心算法,如果数据比较大就要用线段树来维护了. 思路很简单,只要按照代价由大到小排序,然后靠后插入即可.RE了一次,是没想到deadline可以很大.如果d ...

  4. HDU 1009 FatMouse' Trade (贪心算法)

    题意:就是老鼠要用猫粮换粮食,第i个房间一些东西,要用东西去换,可以不全换.问给定的猫粮最多能换多少粮食. 析:贪心算法.我们先算出来每个房间物品的平均价格是多少,肯定越低越好,并且如果能全换就全换, ...

  5. HDU 1789 Doing Homework again(非常经典的贪心)

    Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  6. 题解报告:hdu 1789 Doing Homework again(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has just come back ...

  7. HDU 1789 Doing Homework again (贪心)

    Doing Homework again http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has ...

  8. HDU 1789 Doing Homework again(贪心)

    在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...

  9. HDU - 1789 Doing Homework again(贪心) ~~~学了一波sort对结构体排序

    题目中因为天数和分数是对应的,所以我们使用一个结构体来存分数和截止如期. 一开始做这道题的时候,很自然的就想到对天数排序,然后天数一样的分数从大到小排序,最后WA了之后才发现没有做到"舍小取 ...

随机推荐

  1. android全屏

    this.requestWindowFeature( Window.FEATURE_NO_TITLE ); this.getWindow().setFlags(WindowManager.Layout ...

  2. 【分享】Java学习之路:不走弯路,就是捷径

    1.如何学习程序设计? JAVA是一种平台,也是一种程序设计语言,如何学好程序设计不仅仅适用于JAVA,对C++等其他程序设计语言也一样管用.有编程高手认为,JAVA也好C也好没什么分别,拿来就用.为 ...

  3. Runtime.getRuntime().addShutdownHook(Thread thread) 程序关闭时钩子,优雅退出程序

    根据 Java API, 所谓 shutdown hook 就是已经初始化但尚未开始执行的线程对象.在Runtime 注册后,如果JVM要停止前,这些 shutdown hook 便开始执行.也就是在 ...

  4. PAT甲题题解-1074. Reversing Linked List (25)-求反向链表

    题意说的很清楚了,这种题的话,做的时候最好就是在纸上自己亲手模拟一下,清楚一下各个指针的情况, 这样写的时候就很清楚各个指针变量保存的是什么值. PS:一次AC哈哈,所以说自己动手在纸上画画还是很有好 ...

  5. 【Alpha】第八次Scrum meeting

    今日任务一览: 姓名 今日完成任务 所耗时间 刘乾 学习js并学会使用js读写xml文件.学习python读取xml的方式... 然后上午满课,下午从1点到10点当计组助教去沙河教了一下午+一晚上,所 ...

  6. 20135337朱荟潼 Linux第三周学习总结 ——Linux内核源代码简介

    朱荟潼 + 原创作品转载请注明出处 + <Linux内核分析>MOOC课http://mooc.study.163.com/course/USTC 1000029000 知识笔记 1.ar ...

  7. Leetcode题库——46.全排列

    @author: ZZQ @software: PyCharm @file: permute.py @time: 2018/11/15 19:42 要求:给定一个没有重复数字的序列,返回其所有可能的全 ...

  8. beta5

    吴晓晖(组长) 过去两天完成了哪些任务 完善推荐算法 展示GitHub当日代码/文档签入记录 接下来的计划 推荐算法 还剩下哪些任务 组员:刘帅珍 过去两天完成了哪些任务: 修改原型,整理背景 明日计 ...

  9. 团队作业4--第一次项目冲刺(Alpha版本)日志集合处

    第一次 http://www.cnblogs.com/p-12/p/7861231.html 第二次 http://www.cnblogs.com/p-12/p/7861835.html 第三次 ht ...

  10. 12th 本周工作量及进度统计

    本周PSP: C(类别) C(内容) S(开始时间) ST(结束时间) I(中断时间) T(实际时间) 活动 1日—3日 用户调查 12月1日21:00 12月3日12:00 25小时 14小时 活动 ...