Codeforces D. Stoned Game

outputstandard output
T is playing a game with his friend, HL.

There are n piles of stones, the i-th pile initially has ai stones.

T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.

Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.

Input
The first line of the input contains a single integer t (1≤t≤100) — the number of games. The description of the games follows. Each description contains two lines:

The first line contains a single integer n (1≤n≤100) — the number of piles.

The second line contains n integers a1,a2,…,an (1≤ai≤100).

Output
For each game, print on a single line the name of the winner, “T” or “HL” (without quotes)

Example
inputCopy
2
1
2
2
1 1
outputCopy
T
HL

题意:
有n堆石头,两个人轮流每次拿一个石头。后手不能拿刚刚先手抓的堆.
问:最后谁赢。

题解:
考虑有一个特别大的堆mx,他大于所有其他堆的总和,那么先手只要一直拿这个堆就行
如果上述条件不成立,那么双方博弈过程中肯定都想拿最大的那个堆,比赛过程是确定的,直接奇数偶数。

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t,a[1005],n;
	cin>>t; 
    while(t--)
    {
        cin>>n;
        for(int i=1;i<=n;i++)
        	cin>>a[i];
        int maxx=-1,sum=0;
        for(int i=1;i<=n;i++)
		{
			maxx=max(maxx,a[i]);
			sum+=a[i];	
		} 
		if(maxx>sum-maxx)
		{
			cout<<"T"<<endl;
		}
		else
		{
			if(sum%2)
				cout<<"T"<<endl;
			else
				cout<<"HL"<<endl;
		}
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

henulmh

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值