zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    Clean Code之JavaScript代码示例
    Okhttp3发送xml、json、文件的请求方法
    Ubuntu16.04 开机显示The system is running in low-graphics mode
    DELL R730服务器配置RAID及安装服务器系统 以及域的控制
    centos7搭建rsync
    centos7环境变量配错导致命令不能用
    centos7用lvm扩展xfs文件系统的根分区
    centos查看CPU的数量
    centos7无故重启-内核升级
    ubuntu scp命令或者用root连接ssh提示:Permission denied, please try again.错误
  • 原文地址:https://www.cnblogs.com/tonghao/p/4680517.html
Copyright © 2011-2022 走看看