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

本文共 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

你可能感兴趣的文章
PHP 的 HMAC_SHA1算法 实现
查看>>
Use commons-email-1.1.jar+activation.jar+mail.jar to send Email
查看>>
Android: NDK编程入门笔记
查看>>
深刻理解Linux进程间通信(IPC)
查看>>
windows 7中添加新硬件的两种方法(本地回环网卡)
查看>>
javascript 高级程序设计学习笔记(面向对象的程序设计) 2
查看>>
支配集,点覆盖集,点独立集之间的联系
查看>>
SetCapture ReleaseCapture
查看>>
DataGridView ——管理员对用户的那点操作
查看>>
POJ - 1185 炮兵阵地 (状态压缩)
查看>>
ios7 JavaScriptCore.framework
查看>>
算法6-5:哈希表应用之集合
查看>>
压力单位MPa、Psi和bar之间换算公式
查看>>
Moscow Pre-Finals Workshop 2016. National Taiwan U Selection
查看>>
程序员面试、算法研究、编程艺术、红黑树4大系列集锦与总结 .
查看>>
idea tomcat 配置
查看>>
冲刺第二天
查看>>
LeetCode 405. Convert a Number to Hexadecimal (把一个数转化为16进制)
查看>>
ASP.NET MVC 3–Global Action Filters
查看>>
OFFICE安装提示1935错误
查看>>