(新生赛问题 )B: Alice and Bob

题目描述
Alice and Bob decide to play a game. At the beginning of the game they put n piles of sweets on the table.The number of each pile of sweets may be different. Alice and Bob take away sweets in turn,and always Alice takes sweets first in every games.Each time in their turn they can get only one whole pile of sweets.When there is no sweet left, the game is over. Finally, The man who have the largest number of sweets in hand will win.
Assume that Alice and Bob were very clever.

输入
The first line is an integer n, which means that there are n pile sweets.
1 <= n <= 100000
Next n integers, the i-th integer means the number of sweets in the i-th pile.
The number of sweets in each pile is less than 10000.

输出
If Alice wins, output “A”, and if Bob wins, output “B”.
Otherwise output “again”

样例输入
样例输入1:
3
1 6 7

样例输入2:
4
3 3 3 3

样例输出
样例输出1:

A

样例输出2:
again

刚开始的想法是先冒泡排序,然后奇数时A拿,偶数时B拿,结果程序超时15%,自己写了个快排。。。。结果超时31%!!what?。。。什么都不懂的我束手无策。。
其实仔细想想Bob根本没赢的机会,也不用排序,就找出平局,其他的都输出A赢就行了。。扎心

#include <stdio.h>
int main()
{
	int n;
	int A=0,B=0;
	int temp;
	int a[100001];
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		if(i%2!=0)
		A=A+a[i];
		else if(i%2==0)
		B=B+a[i];
	}
	if(A==B)
	printf("again");
	else
	printf("A"); 
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值