[HDU1789]-Doing Homework again

来源:互联网 发布:淘宝推广pid 编辑:程序博客网 时间:2024/04/30 00:17

Doing Homework again

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

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.
 

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组数据,一组数据分三行,第一行代表的是几个科目,第二行分别是每个科目的期限,接下一行与
上面一行对应如果在期限之内不能完成就要扣除分数,现在需要求得扣除的最小分数。解题思路:这么想,要合理安排并获得最小分数,我们需要把学分多的放在期限内完成,这样一想此题就是贪心思想,
每次把分数大的安排在期限之前,并把此天进行标记,每次得到循环一个科目,我们只需要判断它期限之前的时间有
没有空闲时间是没被安排的,如果有的话,就把安排此科目,并标记这天已经被利用。code如下:
<span style="color:#cc6600;">#include <cstdio>#include <cstring>#include <iomanip>#include <cstdlib>#include <cmath>#include <cctype>#include <iostream>#include <set>#include <map>#include <stack>#include <list>#include <vector>#include <queue>#include <algorithm>#include <utility>using namespace std;typedef long long LL;const double PI = acos(-1);const double eps = 1e-8;const int INF = 0x3f3f3f3f;const int MAXN = 200000+10;const int MAXM = 1000000;const int MOD = 1000000007;#define CLR(a,b) memset((a),(b),sizeof(a))template<typename T>inline T minn(T a,T b,T c){return (a=(a>b)?b:a)>c?c:a;}template<typename T>inline T maxx(T a,T b,T c){return (a=(a>b)?a:b)>c?a:c;}bool dp[MAXN];struct node{int reducescore,deadline;}hmwork[MAXN];bool cmp(node a,node b){return a.reducescore>b.reducescore;}int main(){int n;ios::sync_with_stdio(false);cin >> n;while(n -- ){int m;int deadline;int maxdeadline=-1;cin >> m;for(int i = 0;i < m;++ i)cin >> hmwork[i].deadline;for(int i = 0;i < m;++ i)cin >> hmwork[i].reducescore;sort(hmwork,hmwork+m,cmp);CLR(dp,0);int ans=0;for(int i = 0;i < m;++ i){int tmp = hmwork[i].deadline;//此科目的期限while(dp[tmp]&&tmp>=1){tmp--;}if(tmp<1)ans += hmwork[i].reducescore;//已经找不到时间能安排了elsedp[tmp]=1;//找到了时间安排就进行安排}cout << ans << endl;}}</span>



0 0
原创粉丝点击