hdu1789_Doing Homework again
来源:互联网 发布:腾讯网络主播欣儿照片 编辑:程序博客网 时间:2024/05/22 10:54
Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 12185 Accepted Submission(s): 7162
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
题意:你有n门作业,每门作业需要一天的时间来做,并且这些作业有各自的截止日期 Di ,如果超期未交会扣 Ki 的分数,问你最少能扣多少分?
思路:贪心问题。先做分高的,在截止日期那一天做,如果那一天已经做了分更高的,就去从后向前面找没有做作业的一天,然后把作业做了。现在思考,是否可能我先安排一门分高的作业,导致后面安排的作业会超期。对于这个问题,我们可以想,没门作业都会做一天,所以如果前面安放的会让后面的放不下的话,那么也只会影响后面的一门,而如果我们把后面的课程先做完的话,就会导致前面分高的无法完成,就会扣除更多的分,所以上述的思路是可行的。但是这个题,比较麻烦的是他没有给课程天数的范围。。。有点尴尬,不过我试着开了一个1e7的数组,AC了,说明天数并没有超1e7,所以数据还是很水的。
#include<bits/stdc++.h>using namespace std;struct K{ int day; int score; int real;}s[1050];bool cmp(K a, K b){ return a.score > b.score;}int e[1000000];int main(){ int T; scanf("%d",&T); while(T--){ int n; int sum = 0; memset(e,0,sizeof(e)); scanf("%d",&n); for(int i = 1; i <= n; i++) scanf("%d",&s[i].day); for(int i = 1; i <= n; i++) scanf("%d",&s[i].score); sort(s+1,s+1+n,cmp); for(int i = 1; i <= n; i++){ int flag = 0; for(int j = s[i].day; j >= 1; j--){ if(e[j] == 0){ e[j] = 1; flag =1; break; } } if(!flag) sum += s[i].score; } cout << sum <<endl; }}
0 0
- hdu1789_Doing Homework again
- HDU1789_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
- 文件处理函数
- d3.js学习4----做一个简单的图表
- 手把手入门神经网络系列(2)_74行代码实现手写数字识别
- 剑指offer:树的子结构
- poj 1990 MooFest(树状数组)
- hdu1789_Doing Homework again
- R语言在线地图神器:Leaflet for R包(五) GeoJson文件的使用
- IAP Cannot connect to iTunes Store
- 编译原理 - 课程设计(简易词法分析器)
- 【leetcode】416. Partition Equal Subset Sum
- px、em和rem
- 07-多种链表作业
- XList , simple your list
- Hadoop中dataNode启动不了