寒假训练第二周

Theauthordiscusseschallengesinapplyinglearnedalgorithmstoagameproblem,highlightingtheneedforefficientsolutionstoavoidtimeouts.Focusisonfinding巧妙方法andpracticalimplementation.
摘要由CSDN通过智能技术生成

在第一周的训练过后,学习到了一些较基础的算法,但是相对应的问题仍有很多。比如,一些题相对应的算法知道了,但是实践不出来,导致题也做不出来。

当然,这一周是选拔赛打的比较多,所以还是有一定的感悟。

超时问题,比较难以解决。比如

Alice and Bob are playing a game on a sequence a1,a2⋯an�1,�2⋯�� of length n�. They move in turns, and Alice moves first.

At each player's turn, they should select an integer and remove it from the sequence. The game ends when there is no integer left in the sequence.

Assume the sum of integers selected by Alice is S1�1, and the sum of integers selected by Bob is S2�2.

If the difference between S1�1 and S2 (ie.|S1−S2|)�2 (��.|�1−�2|) is odd, Alice wins; Otherwise, Bob wins.

Your task is to determine who will win the game if both players play optimally.

Input

The first line contains an integer n (1≤n≤106)� (1≤�≤106), indicating the length of the sequence.

The second line contains n� integers a1,a2⋯an (1≤ai≤109)�1,�2⋯�� (1≤��≤109), indicating the elements of the sequence.

Output

The first line output "Alice" (without quotes) if Alice wins and "Bob" (without quotes) otherwise. It is obvious that there is no draw.

#include<bits/stdc++.h>
using namespace std;
int a[1000005];
int main(){
	int n,sum=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
    for(int i=0;i<n;i++){
		if(a[i]%2==1) sum++;
	}
	if(sum%2==1){
		printf("Alice");
	}
	else printf("Bob");
    return 0;	
}

按照题上给的一步一步算的思路,暴力会超时,所以就需要一个取巧的方法去解决。

这周的感悟差不多就是这些,更多是去学习更多的算法并加以实践。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值