博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Hdu 1789 Doing Homework again
阅读量:5082 次
发布时间:2019-06-13

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

Doing Homework again

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 6538    Accepted Submission(s): 3900

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
 

 

Recommend
lcy

 

贪心.

贪心策略:按扣分降序排序,对每个作业进行判断,是否能够在限定的最后一天完成,如果限定的最后一天已经有作业要完成,(如第一个案例:先判断扣10分的作业能不能在第三天完成,此时第三天没有安排作业. 那么就安排进去.接下来再判断第二个作业 也就是扣分为5的作业,第三天已经安排了扣分为10的作业,所以第三天不能再安排作业。往前找,第二天没有安排作业,所以安排到第二天。以此类推)那么继续往前寻找,若前面都不能安排此作业,那么就算这个作业不能完成.

代码如下:

1 #include 
2 #include
3 #include
4 #include
5 using namespace std; 6 #define MAX 1001 7 struct node 8 { 9 int day;10 int score;11 };12 struct node num[MAX];13 bool flag[MAX];14 int n,sum;15 bool cmp(struct node x,struct node y)16 {17 if(x.score==y.score) return x.day
y.score;19 }20 void out()21 {22 for(int i=1;i<=n;i++)23 cout<
<<" ";24 cout<
=1;j--)59 if(flag[j])60 {61 flag[j]=!flag[j];62 ans-=num[i].score;63 break;64 }65 }66 }67 printf("%d\n",ans);68 }69 void solve()70 {71 init();72 read();73 cal();74 }75 76 int main()77 {78 int t;79 scanf("%d",&t);80 while(t--)81 {82 solve();83 }84 return 0;85 }
View Code

 

转载于:https://www.cnblogs.com/By-ruoyu/p/3905568.html

你可能感兴趣的文章
shell中下载最新版本或指定版本的办法(Dockerfile 中通用)
查看>>
极客时间-左耳听风-程序员攻略-分布式架构工程设计
查看>>
akka之种子节点
查看>>
不知道做什么时
查看>>
matlab 给某一列乘上一个系数
查看>>
密码学笔记——培根密码
查看>>
Screening technology proved cost effective deal
查看>>
MAC 上升级python为最新版本
查看>>
创业老板不能犯的十种错误
查看>>
Animations介绍及实例
查看>>
判断请求是否为ajax请求
查看>>
【POJ2699】The Maximum Number of Strong Kings(网络流)
查看>>
spring boot配置跨域
查看>>
BZOJ 1996 合唱队(DP)
查看>>
进击吧!阶乘——大数乘法
查看>>
安卓学习资料推荐-25
查看>>
Mysql数据库备份和还原常用的命令
查看>>
关于退出当前页面在火狐的一些问题
查看>>
【项目实施】项目考核标准
查看>>
spring-aop AnnotationAwareAspectJAutoProxyCreator类
查看>>