hdu1789doing homework again【贪心】
来源:互联网 发布:ida pro 7.0 mac 编辑:程序博客网 时间:2024/06/06 01:00
Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8848 Accepted Submission(s): 5213
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【代码】#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 1100struct homework{int d,s;}hw[maxn];bool cmp(homework x,homework y){if(x.s==y.s) return x.d<y.d;else return x.s>y.s;}int main(){int t,n,i,j,sum,flag[maxn];scanf("%d",&t);while(t--){scanf("%d",&n);for(i=0;i<n;i++) scanf("%d",&hw[i].d);for(i=0;i<n;i++) scanf("%d",&hw[i].s);sort(hw,hw+n,cmp);memset(flag,0,sizeof(flag));sum=0;for(i=0;i<n;i++){for(j=hw[i].d;j>0;j--){if(flag[j]==0){flag[j]=1;break;}}if(j==0) sum+=hw[i].s;}printf("%d\n",sum);}return 0;}
0 0
- hdu1789doing homework again【贪心】
- hdu1789Doing Homework again【贪心算法】
- hdu1789Doing Homework again(贪心)
- HDU1789Doing Homework again(贪心)
- hdu1789Doing Homework again(贪心)
- HDU1789Doing Homework again(贪心+sort)
- HDU1789Doing Homework again
- hdu1789Doing Homework again
- HDU1789Doing Homework again
- Doing Homework again 贪心
- Doing Homework again --贪心
- 【贪心】Doing Homework again
- Doing Homework again 贪心
- 【贪心】Doing Homework again
- Doing Homework again(贪心)
- Doing Homework again 【贪心】
- HDU1789 Doing Homework again 贪心
- 【贪心】 hdu1789 Doing Homework again
- [odroid-pc] ubuntu12.o4编译烧写android4.0 forodroidpc
- EJB学习(一)—EJB概述
- iOS开发之禁用ios7 手势滑动返回功能
- Android系统启动流程 -- android
- 编程之美: 第一章 1.16 24点游戏
- hdu1789doing homework again【贪心】
- Uilabel 字体
- 对称加密算法AES------使用AES算法对文件进行加密/解密的操作(JAVA)
- [二分]poj 1064 Cable Master
- 复用已经打开的iterm链接
- HDU 1251 统计难题 字典树
- sdfdsfdsf
- 图片压缩
- 数据库提高查询效率(较大数据)优化方法