Doing Homework again
来源:互联网 发布:商业数据 200年历史 编辑:程序博客网 时间:2024/05/29 00:33
Doing Homework again
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
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.
输入
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.
输出
For each test case, you should output the smallest total reduced score, one line per test case.
示例输入
333 3 310 5 131 3 16 2 371 4 6 4 2 4 33 2 1 7 6 5 4
示例输出
035
提示
hdoj1789
示例程序
#include<stdio.h> #include<stdlib.h> #include<string.h> struct node { int time,num; }s[1001],f; int cmp(const void *a,const void *b) { struct node *c=(struct node *)a; struct node *d=(struct node *)b; if(c->time!=d->time) return c->time-d->time; else return d->num-c->num; } int main() { int i,j,n,m,k,t,flag[1001],sum,min,temp; while(scanf("%d",&n)!=EOF) { while(n--) { sum=0; scanf("%d",&m); for(i=0;i<m;i++) scanf("%d",&s[i].time); for(i=0;i<m;i++) scanf("%d",&s[i].num); qsort(s,m,sizeof(s[0]),cmp); memset(flag,0,sizeof(flag)); int d=1; temp=0; for(i=0;i<m;i++) { if(s[i].time>=d) { flag[i]=1; d++; } else { min=s[i].num; temp=i; for(j=0;j<i;j++) if(flag[j]==1&&s[j].num<min) { min=s[j].num; temp=j; } sum+=s[temp].num; s[temp].num=s[i].num; } } printf("%d\n",sum); } } }
0 0
- HDU1789:Doing Homework again
- HDU1789--Doing Homework again
- Doing Homework again
- Doing Homework again(dp)
- hdu1789 Doing Homework again
- HDU Doing Homework again
- hdu Doing Homework again
- Doing Homework again
- 【1789 Doing Homework again】
- HDU1789 Doing Homework again
- Doing Homework again
- HDU1789 Doing Homework again
- Doing Homework again
- Doing Homework again 贪心
- Doing Homework again --贪心
- HDU Doing Homework again
- 【贪心】Doing Homework again
- Doing Homework again
- 【鸟哥的linux私房菜-学习笔记】开源软件安装、升级以及函式库相关知识
- 线程同步-临界区、互斥对象、事件对象区别
- 规则引擎Visual Rules Solution—sap函数的调用
- 【2dx】Cocos2dx-sqlite3
- SSH免密码登录方法
- Doing Homework again
- 上传图片裁剪处理-调用android系统自带的裁剪功能
- cordova混合移动app调试工具GapDebug+ripple emulate
- HDU 1160
- BZOJ 3888: [Usaco2015 Jan]Stampede
- linux 负载解惑
- css文件如何注释
- js-innerHTML属性
- 110 AddressBook