D - Doing Homework again扣分最少
来源:互联网 发布:藏地密码 知乎 编辑:程序博客网 时间:2024/04/28 02:53
Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status
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
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 <algorithm>using namespace std;struct p{int day;int score;int flag;}s[1000];int cmp(p a,p b){ if(a.day==b.day) return a.score>b.score; else return a.day<b.day;}int main(){ int T,t; scanf("%d",&T); while(T--) { scanf("%d",&t); int i; for(i=0;i<t;i++) scanf("%d",&s[i].day); for(i=0;i<t;i++) scanf("%d",&s[i].score); for(i=0;i<t;i++) s[i].flag=-1; sort(s,s+t,cmp); int day=1,j,v,min; for(i=0;i<t;i++) { if(day<=s[i].day) { s[i].flag=1; day++; } else { min=s[i].score; v=-1; for(j=i-1;j>=0;j--) { if(s[j].flag==1&&s[j].score<min) { min=s[j].score; v=j; } } if(v>=0) { s[v].flag=-1; s[i].flag=1; } } } int sum=0; for(i=0;i<t;i++) { if(s[i].flag==-1) sum+=s[i].score; } printf("%d\n",sum); } return 0;}
- D - Doing Homework again扣分最少
- 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
- C++vector学习笔记
- depends-工具的用法
- 时光机穿梭
- Android viewpager view
- firewrt,神马神器?
- D - Doing Homework again扣分最少
- WAV文件格式分析
- linux常用命令大全(转)
- NSTimer的使用
- 内核符号表有关问题
- spring 定时器的时间设置
- pat1059 Prime Factors
- 文章标题
- 那些年,我们一起走过的时光