博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
题解报告:hdu 1789 Doing Homework again(贪心)
阅读量:4654 次
发布时间:2019-06-09

本文共 2208 字,大约阅读时间需要 7 分钟。

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

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

解题思路:典型的贪心策略。因为要使得扣分最少,所以要先排个序,规则是:如果期限相同,对扣分多的从大到小排列,如果扣分相同,则将期限从小到大排列。最优策略:每门功课最好在给定的deadline当天就完成,如不能完成,只能往前找哪一天还没使用,尽量使得做这门功课的日期越大越好,即从其截止日期到第一天,如果一路遍历都已经被标记过了,到最后j==0说明已经没有足够的一天时间给他做这门功课,那么就将这门功课扣的分数加到ans中,最终的ans即为最小扣分值。

AC代码:

1 #include
2 using namespace std; 3 struct NODE 4 { 5 int deadline,reduce; 6 }node[1005]; 7 bool cmp(NODE a,NODE b) 8 { 9 if(a.reduce!=b.reduce)return a.reduce>b.reduce;//reduce越多的越靠前,先解决扣分多的10 return a.deadline
>T;17 while(T--){18 memset(vis,false,sizeof(vis));19 cin>>N;20 for(int i=0;i
>node[i].deadline;21 for(int i=0;i
>node[i].reduce;22 sort(node,node+N,cmp);//按规则排序23 ans=0;24 for(int i=0;i
0;j--)//从截止时间开始往前推,如果有一天没用过,这一天就做这一门课,那么这门课不扣分26 if(!vis[j]){vis[j]=true;break;}27 if(j==0)ans+=node[i].reduce;//如果j=0,表明从deadline往前的每一天都被占用了,这门课完不成28 }29 cout<
<

 

转载于:https://www.cnblogs.com/acgoto/p/8526303.html

你可能感兴趣的文章
hdu 2050 折线分割平面
查看>>
[翻译svg教程]svg 中的g元素
查看>>
普通类中能不能有函数模板?/有函数模板的类可以是普通类吗
查看>>
表单输入绑定
查看>>
python学习日记(迭代器、生成器)-乱七八糟
查看>>
ADO.NET数据集的工作原理
查看>>
oracle实现自增长列
查看>>
自我介绍
查看>>
前端组件化
查看>>
转载:C# this.Invoke()的作用与用法 理解三
查看>>
邮件模板——开发篇
查看>>
我和我的广告前端代码(三):一次重来的机会,必要的技术选型
查看>>
react--绑定this三种方式
查看>>
js + css 实现标签内容切换功能
查看>>
做接口自动化时候,一些登录头信息可以通过aop的方式进行增强
查看>>
linux popen函数
查看>>
《OpenGL编程指南》学习进度备忘
查看>>
关于 C# 中 Events 和 Thread Safety
查看>>
C# 推箱子(只有一关)
查看>>
crossapp的屏幕适配
查看>>