J - Cunning Friends 计蒜客41015

J - Cunning Friends

Anthony and his friends Ben and Chris decided to play a game. They have N N N piles of stones such that the i t h i^{th} ith-pile contains A i A_i Ai stones. In one move a player chooses one pile and may take any non-zero number of stones from it. The players take turns. Anthony goes first then Ben and then Chris. If some player cannot make a move (no more stones exist) he loses. Ben colluded with Chris so their goal is to make Anthony lose. But Anthony doesn’t want to lose. You have to find out if Anthony can avoid defeat if all players play optimally.

Input
The first line contains one integer N N N ( 1 ≤ N ≤ 1 0 5 ) (1 \le N \le 10^5) (1N105).

The next line contains N N N integers A i A_i Ai ( 1 ≤ A i ≤ 1 0 9 ) (1 \le A_i \le 10^9) (1Ai109).

Output
Print “Lose” if Anthony will lose in this game and “Win” otherwise.

题目链接:https://nanti.jisuanke.com/t/41015

题目大意:普通的nim游戏,A,B,C三个人玩,B和C一起针对A,问A先走有无必胜策略。

解题思路:湖南多校第二第二场J题博弈论。普通的nim游戏仅通过sg函数异或就可以得到答案。此题考虑二人针对一人。发现在堆数N(>=2)且 每堆含石子数(>=2) 时 可以证明 A必输。其他情况可以划归到已知情况。只需分类讨论含1个石子的堆数、含2个石子的堆数和多个石子的堆数,就能得到答案。

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
   int n;
   scanf("%d",&n);
   int a=0,b=0,c=0;
   for (int i=1;i<=n;i++){
   	 int x;
   	 scanf("%d",&x);
   	 if (x==1) a++;
   	 if (x>1) b++;
   	 if (x==2) c++;
   }
   a=a % 3;
   int flag=1;
   if (a==0 && b==1) { puts("Win"); flag=0;}
   if (a==1 && b==0){ puts("Win"); flag=0;}
   if (a==1 && b==1) { puts("Win"); flag=0;}
   if (a==1 && b==2 && c!=0) { puts("Win"); flag=0;}	
   if (a==2 && b==0){ puts("Win"); flag=0;}
   if (a==2 && b==1){ puts("Win"); flag=0;}
   if (a==2 && b==2 && c!=0){ puts("Win"); flag=0;}	
   if (flag==1) puts("Lose");		  
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值