1472D - Even-Odd Game

链接:

https://codeforces.com/problemset/problem/1472/D

题意:

n个正整数的数组a,A,B玩游戏,规则如下:

  • AB轮流,A先。
  • 每个回合选择任何元素并将其从数组中移除。
  • 如果A选择偶值然后她把它加到她的分数里。如果选择的值是奇数,那么A的分数不会改变。
  • 同样,如果B选择奇值然后他把它加到他的分数里。如果选择的值为偶数,则B的得分不变。

输入

4
4
5 2 7 3
3
3 2 1
4
2 2 2 2
2
7 8

输出量

Bob
Tie
Alice
Alice

解:

思维:

从大到小排,然后遍历,A,B轮流,A先,判断该数字是否能加分,能加分加入总和(ll),不能加也不能给对手。(给对手等于扣分)

实际代码:

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<bits/stdc++.h>
#define csh(a) memset(a,0,sizeof(a))
using namespace std;
typedef long long int ll;
const int N=2E5+5;
int a[N];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int t;
	cin>>t;
	for(int f=1;f<=t;f++)
	{
		csh(a);
		int n;
		cin>>n;
		ll ag=0,bg=0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		sort(a+1,a+n+1,cmp);
		for(int i=1;i<=n;i++)
		{
			if(i%2==1)//AÏÈ
			{
				if(a[i]%2==0) ag+=a[i];
				else continue;
			}
			else //B
			{
				if(a[i]%2==0) continue;
				else bg+=a[i];
			}
		}
		if(ag>bg) cout<<"Alice"<<endl;
		if(ag==bg) cout<<"Tie"<<endl;
		if(ag<bg) cout<<"Bob"<<endl;
	}
}

限制:

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值