链接:
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