hdu 1789 Doing HomeWork Again (贪心算法)
题目链接: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 (贪心算法)的更多相关文章
- HDU 1789 - Doing Homework again - [贪心+优先队列]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...
- HDU 1789 Doing Homework again(贪心)
Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...
- hdu 1789 Doing Homework again (Greedy)
Problem - 1789 继续贪心.经典贪心算法,如果数据比较大就要用线段树来维护了. 思路很简单,只要按照代价由大到小排序,然后靠后插入即可.RE了一次,是没想到deadline可以很大.如果d ...
- HDU 1009 FatMouse' Trade (贪心算法)
题意:就是老鼠要用猫粮换粮食,第i个房间一些东西,要用东西去换,可以不全换.问给定的猫粮最多能换多少粮食. 析:贪心算法.我们先算出来每个房间物品的平均价格是多少,肯定越低越好,并且如果能全换就全换, ...
- HDU 1789 Doing Homework again(非常经典的贪心)
Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 题解报告:hdu 1789 Doing Homework again(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has just come back ...
- HDU 1789 Doing Homework again (贪心)
Doing Homework again http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has ...
- HDU 1789 Doing Homework again(贪心)
在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...
- HDU - 1789 Doing Homework again(贪心) ~~~学了一波sort对结构体排序
题目中因为天数和分数是对应的,所以我们使用一个结构体来存分数和截止如期. 一开始做这道题的时候,很自然的就想到对天数排序,然后天数一样的分数从大到小排序,最后WA了之后才发现没有做到"舍小取 ...
随机推荐
- Hiberante持久化对象的3种状态
近日一同事问我关于Hibernate中对象的3种状态的问题,因此特意总结一下.在Hibernate中对象是有以下3中状态: 瞬时态(transient object): 没有OID值,没有被s ...
- OFS环境,删除Resource 时出现错误失败,应该如何继续
From the Windows failover cluster manager,select the group listener, stop it, and delete it. Do the ...
- Kubernetes学习之路(十九)之Kubernetes dashboard认证访问
Dashboard:https://github.com/kubernetes/dashboard 一.Dashboard部署 由于需要用到k8s.gcr.io/kubernetes-dashboar ...
- 微信小程序之路由
1. 路由方式 路由方式 触发时机 路由前页面 路由后页面 初始化 小程序打开的第一个页面 onLoad, onShow 打开新页面 调用 API wx.navigateTo 或使用组件 onHide ...
- 记一次Java加密加签算法到php的坑
此文为本人原创首发于 http://www.35coder.com/convert_encryption_codes_to_php/. 写代码的经历中,总少不了与外部的程序对接,一旦有这样的事,往往周 ...
- 3dmax2020下载安装3dmax2020破解中文版下载安装
3dmax在室内设计.建筑设计领域是最专业的效果图制作软件,也是在游戏动画等领域中在场景方面最专业的软件,目前最新3dmax2020版本已出,我分享亲测好用的软件包,拿走不谢! 3dmax2020安装 ...
- [Unity]制作游戏中名字板的过程记录
先大概说一下需求: 1 每个模型上都要有名字板:人.怪.npc等等. 2 名字板上会显示:名字(文字).血条(图片)等 3 因为是透视相机,名字板离得太近会变得超大,且主角移动,名字板的位置相对于相机 ...
- D. Vasya and Arrays
链接 [http://codeforces.com/contest/1036/problem/D] 题意 给你两个数组长度分别为n,m; 有这么一种操作,用某个数组的某个子区间元素之和代替这个子区间, ...
- Alpha版本项目展示要求(加入模板)
Alpha版本展示的时间暂定为11月17日课上,提前到13:00开始.如有变动,另行通知. Alpha版本项目展示要求如下: 不得使用PPT,展示所用的资料必须发表在博客上. 现场演示你们发布的软件. ...
- Android开发环境(发展演变)
初步接触android,要安装android开发工具时是使用eclipse,这是因为百度靠前的搜索项是eclipse来开 发android,而且那时还不知道android studio. 首先是下载配 ...