列表

详情


NC205340. YetAnotherStonesGame

描述

One day, Little Gyro and Derrick are playing a game with stones again.
There are N (N is always an even number) piles of stones. The i-th pile contains a_i stones.
In one's turn, the player should choose exactly non-empty piles and take any positive number of stones away for each pile he chooses. That means the player can remove stones within a different number from all the selected piles in a single turn.
And in this game, suppose that the two players, Little Gyro and Derrick, are all very clever. Little Gyro always takes first. The person who cannot make a move loses the game.
Now given the number of the stones of N piles, if both of them play the game optimally, your job is to tell who will win the game.

输入描述

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains an one integer N (2 ≤ N ≤ 50), indicating the number of the piles.
The second line contains N numbers a_1, a_2,……, a_n (1 ≤ a_i ≤ 50), indicating the number of the stones in the i-th pile.

输出描述

For each case, output "Happy Little Gyro"(without quotes) if Little Gyro wins the game, Otherwise, output "Sad Little Gyro"(without quotes).

示例1

输入:

2
2
8 8
4
3 1 4 1

输出:

Sad Little Gyro
Happy Little Gyro

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++ 解法, 执行用时: 3ms, 内存消耗: 380K, 提交时间: 2021-05-24 16:17:29

#include<bits/stdc++.h>
using namespace std;
int a[55];
int main()
{
    int t, n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i = 1; i <= n; i++)
            cin>>a[i];
        sort(a+1, a+1+n);
        if(a[1] == a[n/2+1])
            cout<<"Sad Little Gyro"<<endl;
        else
            cout<<"Happy Little Gyro"<<endl;
    }
    return 0;
}

C++14(g++5.4) 解法, 执行用时: 3ms, 内存消耗: 376K, 提交时间: 2020-09-18 16:45:00

#include<bits/stdc++.h>
using namespace std;
int sz[55];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		for(int i=0;i<n;i++)
		{
			cin>>sz[i];
		}
		sort(sz,sz+n);
        if(sz[0]==sz[n/2])
        {
            cout<<"Sad Little Gyro\n";
        }
        else
        {
           cout<<"Happy Little Gyro\n"; 
        }
	}
}

上一题