• hdoj 1789 Doing Homework again


    Doing Homework again

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


    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
    先对分数从大到小排序 然后设出一个数组vis[]来按照分数从高到低记录必须占用的日期如果有空闲的日期
    则标记为1 若没有空闲的日期则舍弃这个分数
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    struct record
    {
    	int day;
    	int score;
    }num[1100];
    bool cmp(record a,record b)
    {
    	if(a.score!=b.score)
    	return a.score>b.score;
    	else
    	return a.day<b.day; 
    }
    int main()
    {
    	int n,m,j,i,t,l,sum;
    	int vis[1100];//用来储存必须要占用的日期 
    	scanf("%d",&t);
    	while(t--)
    	{
    		scanf("%d",&n);
    		memset(vis,0,sizeof(vis));
    		for(i=0;i<n;i++)
    			scanf("%d",&num[i].day);
    		for(i=0;i<n;i++)
    		    scanf("%d",&num[i].score);
    		sort(num,num+n,cmp);
    		sum=0;
    		for(i=0;i<n;i++)
    		{
    			for(j=num[i].day;j>=1;j--)
    			{
    				if(vis[j]==0)
    				{
    					vis[j]=1;
    					break;
    				}
    			}
    			if(j==0)
    			sum+=num[i].score;
    		}
    		printf("%d
    ",sum);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    面试数据分析岗,怎么提升一倍成功率?让过来人给你支支招
    SQL执行效率提升几万倍的操作详解!
    记一次因Redis使用不当导致应用卡死过程
    运筹学那些事,专科学生学习运筹学之运输问题,No.5
    如何在C++中嵌入JAVA
    国际站中国区,孟买上Redis 4.0 集群版
    国际站中国区,孟买上Redis 4.0 集群版
    国际站中国区,孟买上Redis 4.0 集群版
    国际站中国区,孟买上Redis 4.0 集群版
    attachEvent与addEventlistener兼容性
  • 原文地址:https://www.cnblogs.com/tonghao/p/4680517.html
Copyright © 2020-2023  润新知