hdu 1789 Doing Homework again

/*
第一步:按分值排序;
第二步:按分值优先更新同一期限作业的时间;
处理方法:同一期限按照分值严格递减降低其最后期限;
数据:
7
1 4 6 4 2 4 3
3 2 1 7 6 5 4
处理过程:
4 2 4 3 1 4 6
7 6 5 4 3 2 1
  
4 2 4 3 1 4 6
7 6 5 4 3 2 1
  
4 2 3 3 1 2 6
7 6 5 4 3 2 1
  
4 2 3 2 1 2 6
7 6 5 4 3 2 1
  
4 2 3 1 1 0 6
7 6 5 4 3 2 1
  
4 2 3 1 0 0 6
7 6 5 4 3 2 1
5
结果:将期限小于等于0的分值相加
*/

Doing Homework again

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3017    Accepted Submission(s): 1727


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
3 3 3 3 3 10 5 1 3 1 3 1 6 2 3 7 1 4 6 4 2 4 3 3 2 1 7 6 5 4
 

Sample Output
0 3 5
 

Author
lcy
 

Source
 

Recommend
lcy
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int x[1010];
struct node{
    int a;
    int b;
}map[1010];
int cmp(node x,node y)
{
    return x.b>y.b;
}
int main()
{
    int i,j,k,n,T;
    cin>>T;
    while(T--)
    {
        cin>>n;
        for(i=1;i<=n;i++)
        {
            cin>>map[i].a;
        }
        for(i=1;i<=n;i++)
        {
            cin>>map[i].b;
        }
        sort(map+1,map+n+1,cmp);
        for(i=n;i>=1;i--)
        {
            int k=0;
            for(j=1;j<=n;j++)
            {
                if(map[j].a==i)
                {
                    x[k++]=j;
                }
            }
            for(j=k-1;j>=0;j--)
            {
                map[x[j]].a-=j;
            }
        }
        int Max=0;
        for(i=1;i<=n;i++)
        {
            if(map[i].a<=0) Max+=map[i].b;
        }
        cout<<Max<<endl;
    }
    return 0;
}

 

 
posted @ 2012-08-13 09:35  zyh123101  阅读(132)  评论(0编辑  收藏  举报