hdoj-1789-Doing Homework again
来源:互联网 发布:林俊杰 睡粉 知乎 编辑:程序博客网 时间:2024/05/22 14:39
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.
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
333 3 310 5 131 3 16 2 371 4 6 4 2 4 33 2 1 7 6 5 4
Sample Output
035
有t组测试数据,每组测试数据中有n门功课,第一排完成它们的时间限制,第二排是未在限制的时间内完成的要扣除的分数,然后是需要求扣的分数最少。
很经典的贪心啊
对分数按从大到小排次序,然后枚举限定的时间,若是某一天没有被标记,就用这一天来完成这一门作业,若是枚举到0了,说明在限定时间内没有哪一天可以完成这门作业,那么就扣除这门课的分数
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;struct ss{ int time,p;}t[100000];int f[100000];int cmp(const ss a,const ss b){ if(a.p>b.p) return 1; else if(a.p==b.p&&a.time<b.time) return 1; else return 0;}int main(){ int text,n; scanf("%d",&text); while(text--) { scanf("%d",&n); memset(f,0,sizeof(f)); int i,j; for(i=1;i<=n;i++) scanf("%d",&t[i].time); for(i=1;i<=n;i++) scanf("%d",&t[i].p); sort(t+1,t+1+n,cmp); int sum=0; for(i=1;i<=n;i++) { for(j=t[i].time;j>=1;j--) if(!f[j]) { f[j]=1; break; } if(j==0) sum+=t[i].p; } printf("%d\n",sum); } return 0;}
0 0
- HDOJ 1789 Doing Homework again
- hdoj 1789 Doing Homework again
- hdoj 1789 Doing Homework again
- hdoj 1789 Doing Homework again
- HDOJ 1789 Doing Homework again
- HDOJ-1789 Doing Homework again
- hdoj 1789 Doing Homework again
- hdoj-1789-Doing Homework again
- HDOJ 1789 Doing Homework again
- HDOJ 1789 Doing Homework again
- HDOJ 1789 Doing Homework again
- HDOJ-1789 Doing Homework again
- HDOJ 1789 Doing Homework again
- HDOJ 1789 Doing Homework again
- HDOJ 1789 Doing Homework again
- HDOJ 1789 Doing Homework again贪心
- HDOJ 1789 Doing Homework again (贪心)
- hdoj 1789 Doing Homework again 【贪心】
- 理解dropout
- 二分+树型 dp hdu5682 zxa and leaf
- angularjs-表单验证
- JS大总结(带实例)
- 消息中间件及WebSphere MQ入门
- hdoj-1789-Doing Homework again
- 键盘按钮keyCode大全
- SpringMVC annotation注解版helloworld
- 北京市工作居住证官方网站js报错不能使用解决办法
- HDU 5680 zxa and set
- Oracle 查询每天执行慢的SQL
- c++引用
- Windows Xp和openSUSE 11.2双系统硬盘安装指南 (参考)
- Spring中@Transactional用法