HDU - 1789 Doing Homework again 贪心

Doing Homework again

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


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


这题与 HDU - 1051 题 思路差不多,先将数组按扣分多少从大到小排序,扣分相同时将时间按从小到大排,然后循环求解。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct dead{
	int day,red;
};

bool cmp(dead a, dead b)
{
	if (a.red!=b.red)
		return a.red > b.red;
	return a.day < b.day;
}
int wri[1005];
int main()
{
	int T,N;
	scanf("%d", &T);
	struct dead line[1005];
	while (T--)
	{
		scanf("%d", &N);
		for (int i = 0; i < N; i++)
		{
			scanf("%d", &line[i].day);
		}
		for (int i = 0; i < N; i++)
		{
			scanf("%d", &line[i].red);
		}
		sort(line, line + N, cmp);
		int sum = 0,j=0;
		memset(wri, 0, sizeof(wri));
		for (int i = 0; i < N; i++)
		{
			j = line[i].day;
			while (j)
			{
				if (!wri[j])//判断这天是否写过作业
				{
					wri[j] = 1;
					break;
				}
				j--;
			}
			if (j == 0)
				sum += line[i].red;
		}
		printf("%d\n", sum);
	}
	return 0;
}


全部评论

相关推荐

不愿透露姓名的神秘牛友
07-10 14:00
林子大了什么鸟都有啊,我觉得我说的已经很客气了,阴阳谁呢
牛客62656195...:应该不是阴阳吧?你第一次注册的时候boss就说你是牛人
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-09 12:05
点赞 评论 收藏
分享
程序员小白条:找的太晚,别人都是大三实习,然后大四秋招春招的,你大四下了才去实习,晚1年
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 13:35
虽然不怎么光彩,经过这件事,可能我真的要去认同“面试八股文早该淘汰!不会用AI作弊的程序员=新时代文盲!”这句话了
HellowordX:Ai的出现是解放劳动力的,不是用来破坏公平竞争环境的,这样下去,轻则取消所有线上面试,严重了会影响整个行业对所有人产生影响,企业会拉高入职考核各种离谱考核会层出不穷
你找工作的时候用AI吗?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务