洛谷链接:
Stoned Game - 洛谷https://www.luogu.com.cn/problem/CF1396B
思路见代码和注释:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int t, n, a[maxn];
int main(){
cin >> t;
while(t--){
cin >> n;
for(int i=1; i<=n; i++){
cin >> a[i];
}
sort(a+1, a+n+1);
int sum = 0;
for(int i=1; i<=n-1; i++){
sum += a[i];
}
//极端情况(其中一堆比其他加起来还要多)
//此时先手直接选这一堆,并且一直在这里取,就必定能赢
if(sum < a[n]) {cout << "T" << endl; continue;}
//一般情况(当前可以贪心的选最多的那一堆,避免给到对面极端情况)
//两人都不断选最多的一堆,最终必定导致所有堆取到0,所以看奇偶性即可
sum += a[n];
if(sum % 2 == 0) cout << "HL" << endl;
else cout << "T" << endl;
}
}