贪心初步-A - Doing Homework again

Doing Homework again

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


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
 
对于其他人来说这是一道再简单不过的水题,但是对于我来说,我是尝试了很多遍都没成功,刚开始头脑简单地直接用优先队列去做排序标准则定成分数除以截至日期,但是无法得到整体的最优解,因为这是一个很荒谬的定法,脱离了题目所定下的条件。所以后来经过讨论,我终于发现应当按照先有一个变量作为时间线,每个最终期限都填入时间线,每个最终期限里都填入这个期限对应的最大的分数,然后空出来的日子里就填入剩下时间期限未到的元素中分值最大的。这样剩下的元素就是所要的答案。
其实还可以先把所有要扣除的分数都加在一起,然后逐个减掉所要扣除的分数。然后得到最优解。
下面插入还没有写好的的代码,即错误的初步代码。其实应该用vector容器来做,自己写好排序规则利用qsort函数。
#include<cstdio>
#include<string>
#include<cstdlib>
#include<queue>
#define maxn1 1005
#define maxn2 1005
using namespace std;

struct Work{	
	int daat,score;
	double va;
}ha[maxn1];
bool operator < (struct Work a,struct Work b){
	if(a.daat != b.daat){
		if(a.daat > b.daat)
			return	true;
		else
			return false;
	}else{
		if(a.score < b.score)
			return	true;
		else
			return	false;
	}
}
int main(){
	int t,n;
	int wor;
	scanf("%d",&t);
	while(t--){
		priority_queue<struct Work> lis;
		scanf("%d",&n);
		for(int i = 0;i < n;i++){
			scanf("%d",&ha[i].daat);		
		}
		for(int i = 0;i < n;i++){
			scanf("%d",&ha[i].score);
		}
		int fuck = 0;
		for(int i = 0;i < n;i++){
			ha[i].va = ha[i].score*1.0 /ha[i].daat;
			lis.push(ha[i]);
			fuck += ha[i].score;
		}
		int useddate = 1;
		while(!lis.empty() && fuck >= 0){
			struct Work t;
			t = lis.top();
			if(t.daat == useddate){
				lis.pop();
				fuck -= t.score;
				useddate++;
			}
			else if(t.daat < useddate){
				lis.pop();
			}
			else if(t.daat > useddate){             //此循环内的问题出在如何找到剩余元素中的最大值。
				struct Work temp;
				temp = t;
				int blw = t.score;
				while(){
					
				}
				fuck -= blw;
				useddate++;
			}
		}
		printf("%d\n",fuck);
	}
	return	0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值