2012百度之星初赛第二场ProblemC

//2012百度之星初赛第二场ProblemC
//这题用是贪心,按照差值从大到小排序,差值相同的按两种礼物得分总和从大到小排序
//然后大的优先选择礼物
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
struct Friend{
	int a, b;
	int x, y;
	int dlt;
}friends[1010]; //a,b为两种礼物的好感度,dlt为两种礼物好感度值之差
int nN, a[2], b[2], nA, nB;
bool cmp(Friend a, Friend b){
	if(a.dlt > b.dlt)
		return true;
	else if(a.dlt < b.dlt)
		return false;
	else
		return a.a + a.b > b.a +b.b;
}//差值从大到小排序,差值相同的按两种礼物好感度总和从大到小排序
inline int max(int a, int b){
	return a > b ? a : b;
}
int main(){
	
	while(cin >> nN){
		for(int i = 0; i < nN; i++){
			scanf("%d %d", &friends[i].x, &friends[i].y);
		}//输入所有人的x和y
		cin >> nA >> a[0] >> b[0];//第一个礼物的A,B值
		cin >> nB >> a[1] >> b[1];//第二个礼物的A,B值
		for(int i = 0; i < nN; i++){
			friends[i].a = friends[i].x * a[0] + friends[i].y * b[0];
			friends[i].b = friends[i].x * a[1] + friends[i].y * b[1];
			friends[i].dlt = friends[i].a > friends[i].b ? friends[i].a - friends[i].b :friends[i].b - friends[i].a;
		}//计算两种礼物分别多少好感度
		sort(friends, friends + nN, cmp);//排序
		int ans = 0;
		for(int i = 0; i < nN; i++){
			if(nA && nB){//dlt大的优先选择礼物
				if(friends[i].a > friends[i].b){
					ans += friends[i].a;
					nA--;
				}else if(friends[i].a < friends[i].b){
					ans += friends[i].b;
					nB--;
				}
			}else if(nA){//只剩下第一种礼物
				ans += friends[i].a;
			}else{//只剩下第二种礼物
				ans += friends[i].b;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值