Doing Homework again 贪心
来源:互联网 发布:假面骑士ooo网络特别版 编辑:程序博客网 时间:2024/05/21 09:26
Doing Homework again
题目描述
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<iostream>using namespace std;struct homework{ int deadline, reduce;}a[1000], b;void quick_sort(homework s[], int l, int r){ if(l < r){ int i=l, j=r, x=s[l].deadline, y=s[l].reduce; b = s[l]; while(i < j){ while(i < j && (s[j].deadline > x || (s[j].deadline==x && s[j].reduce<y ) ) ) j--; if(i < j) s[i++] = s[j]; while(i < j && (s[i].deadline < x || (s[j].deadline==x && s[j].reduce>y ) ) ) i++; if(i < j) s[j--] = s[i]; } s[i] = b; quick_sort(s, l, i-1); quick_sort(s, i+1, r); }}int main(){ int t; while(cin>>t) { while(t--){ int n, i, Date = 1, score=0; cin>>n; for(i=0; i<n; i++) cin>>a[i].deadline; for(i=0; i<n; i++) cin>>a[i].reduce; quick_sort(a, 0, n-1); for(i=0; i<n; i++){ if(a[i].deadline >= Date) { Date++; continue; } int decline = a[i].reduce; for(int j=0; j<i; j++) if(a[j].reduce < decline ) decline = a[j].reduce; score += decline; } cout<<score<<endl; } } return 0;}
0 0
- 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
- hdu17891 Doing Homework again 贪心
- 贪心算法-Doing Homework again
- hdu1789 Doing Homework again (贪心)
- 贪心之Doing Homework again
- HDU1789 Doing Homework again 【贪心】
- hdu1789(Doing Homework again 贪心)
- [HDU1789]Doing Homework again[贪心]
- HDU1789:Doing Homework again 【贪心】
- HDU1789 Doing Homework again(贪心)
- 2.简单工厂模式
- 打包H264码流到FLV文件
- guava有感
- 最少拦截系统 贪心
- C/C++上二维数组的两种动态分配内存方法
- Doing Homework again 贪心
- 第十八周项目1-3:删除首结点
- Lua源代码阅读(二)string的实现
- 使用真机调试时的问题。
- 解析oracle的rownum
- Linux内核学习(一)8086编程模型
- 集训小记 8
- Hadoop2.5.1在Ubuntu14中的伪分布配置+wordcount测试+eclipse环境配置
- 迷瘴 贪心