Stoned Game

52 篇文章 1 订阅

https://codeforces.com/contest/1397/problem/D

T is playing a game with his friend, HL.

There are nn piles of stones, the ii-th pile initially has aiai 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 tt games, determine the winner of each game.

Input

The first line of the input contains a single integer tt (1≤t≤100)(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 nn (1≤n≤100)(1≤n≤100) — the number of piles.

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

Output

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

Example

input

Copy

2
1
2
2
1 1

output

Copy

T
HL

Note

In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 11 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.


思路:在纸上枚举一些数字比较小的状态可以发现一些必胜状态,然后其他状态就是往这个必胜状态转化。容易发现取当前序列中数字最大的进行博弈是最优的。

然后优先队列模拟一下。注意一下取top的时候要判当前的size(),不然会访问到非常奇怪的东西

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=200;
typedef long long LL;
LL a[maxn];
void solve()
{
	LL n;cin>>n;
	priority_queue<LL>q;//默认大根堆 
	for(LL i=1;i<=n;i++){
		cin>>a[i];q.push(a[i]);	
	} 
	if(n==1) {
		cout<<"T"<<endl;return;
	}
	LL flag=1;//轮到T
	LL u=0;LL v=0; 
	while(q.size())
	{
		//取前判断空不空 
		if(q.size()){
		 u=q.top();q.pop();
		 u--;
		 flag=-1;//轮到HL拿
		}
		if(q.size()){	
		 v=q.top();q.pop();
		 v--;
		 flag=1;//轮到T拿
		}
		if(u>0) q.push(u);
		if(v>0) q.push(v);
        
	}
	if(flag==1) cout<<"HL"<<endl;
	else cout<<"T"<<endl;
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--)
  {
  	 solve();
  }
return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值