Gym - 101808I Ildar Yalalov

Ildar Yalalov is a famous eagle with the head of an uzbek guy. He is a very famous competitive programmer in Russia.

But what people don't know that his friend Sergey was feeding him for 3 months so that his wings grow. Few months ago Yalalov was in the top 20 in some VK cup round. In the next round he missed solving 1 problem because he forgot how to use setprecision function properly.

Sergey was very angry, because he spent all these months training Yalalov and growing his wings but for nothing so he decided to quit that and moved on to some other talented guys.

Ildar decided to challenge Sergey to some game to prove that Sergey is no more than a beginner problem-solver.

There are N piles of stones, the ith pile contains Ai stones. Ildar and Sergey are playing a game, they take turns and Ildar starts the first move.

In each turn, the current player has two options:

1) Remove one stone from any pile.

2) Remove one stone from every pile if every pile has at least 1 stone.

The player who can't make a move loses. Can you determine the winner if both players play optimally?

Print "Yalalov" if Ildar Yalalov wins, and "Shin" otherwise.

Input

The first line contains a single integer T, the number of test cases.

Each test case starts with a line containing a single integer N, the number of piles. (1 ≤ N ≤ 100)

The following line contains N space-separated integers Ai, the number of stones in each pile. (1 ≤ Ai ≤ 106)

Output

For each test case, print "Yalalov" if Ildar Yalalov wins the game, and "Shin"otherwise.

Example

Input

1
2
1 2

Output

Yalalov

题意:n堆石子,两种操作方式,Ildar先操作,无法进行任何操作的一方失败。操作1:任意拿走某一堆石子中的一颗。操作2:拿走每一堆石子中的一颗(每一堆石子都至少有一颗)。给出n堆石子的数量,若lldar胜利输出 Yalalov ,反之输出 Shin

思路:记所有石子的总数为sum,分为四种情况。在这之前明确,当无法进行操作2的时候,双方谁面临的石子是奇数谁胜利。

(1)当n为奇数,sum为奇数

n为奇数,操作一拿走的石子数量为1,操作二拿走的石子数量为n(当操作二可以执行的时候),两个操作都是拿走奇数的石子,那么先行者,每次操作,剩下的石子数量sum都为偶数,后行者,不论进行哪个操作,剩下的石子数量sum都为奇数,所以先行者胜利。

(2)当n为奇数,sum为偶数

n为奇数,操作一拿走的石子数量为1,操作二拿走的石子数量为n(当操作二可以执行的时候),两个操作都是拿走奇数的石子,那么先行者,每次操作,剩下的石子数量sum都为奇数(这样状态就转移到了第一个情况),后行者,不论进行哪个操作,剩下的石子数量sum都为偶数,所以后行者胜利。

(3)当n为偶数,sum为奇数,记录最小的一堆石子数量为min

n为偶数,操作一拿走的石子数量为1,操作二拿走的石子数量为n(当操作二可以执行的时候),能否进行操作二(取走偶数个的石子),取决于最小石子数min,为了取胜,要对手操作后,自己改变最小一堆的奇偶性。这里讲不太清楚,建议直接用简单的例子来判断胜负,这里不论min为奇数还是偶数,都是先行者胜利。

(4)当n为偶数,sum为奇数

同上,自己写几个例子,会发现当min为奇数,先行者胜利,当min为偶数,后行者胜利。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		int i;
		int a[110];
		int sum=0;
		for(i=1;i<=n;i++){
			scanf("%d",&a[i]);
			sum+=a[i];
		}
		sort(a+1,a+1+n);
		int x=a[1];
		if(n%2==1){
			if(sum%2==1){
				printf("Yalalov\n");
			}
			else{
				printf("Shin\n");
			}
		}
		else{
			if(sum%2==1){
				printf("Yalalov\n");
			}
			else{
				if(x%2==1)printf("Yalalov\n");
				else printf("Shin\n");
			}
		}
	}
	return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值