拿物品

原题地址:https://ac.nowcoder.com/acm/contest/3003/F

解题思路
因为题意希望得分差最大,设牛牛为N,牛可乐为M,(N-M)增加,则N增加,M减少,即牛牛拿到的ai增加,牛可乐拿到的bi减小,反之牛牛拿到的bi增加,故计算出ai+bi的值,对ai+bi进行从小到大排序,奇数给牛牛,偶数给牛可乐

AC代码

#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 200000;
typedef long long ll;
struct cole
{
	ll value;
	int id;
};
cole coles[maxn];
int x;

bool cmp(cole a,cole b)//从大到小排
{
	return a.value>b.value;
}

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < 2*n; i++)
	{
		scanf("%d", &x);
		coles[i%n].value+=x;
	}
	for(int i = 0;i<n;i++)
	{
		coles[i].id = i+1;
	}
	sort(coles,coles+n,cmp);//添加一个cmp,可以排序自定义结构
	for (int i = 0; i < n; i += 2)
	{
		printf("%d ", coles[i].id);
	}
	printf("\n");
	for (int j = 1; j < n; j += 2)
	{
		printf("%d ", coles[j].id);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值