• E - Stoned Game


    T is playing a game with his friend, HL.

    There are nn piles of stones, the ii-th pile initially has a_iai​ 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 \le t \le 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 \le n \le 100)(1≤n≤100) — the number of piles.

    The second line contains nn integers a_1, a_2, \dots, a_na1​,a2​,…,an​ (1 \le a_i \le 100)(1≤ai​≤100).

    Output

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

    Sample 1

    InputcopyOutputcopy
    2
    1
    2
    2
    1 1
    
    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.

    1. #include<iostream>
    2. #include<algorithm>
    3. #include<map>
    4. #include<cstring>
    5. #include<vector>
    6. #include<cmath>
    7. #include<cstdlib>
    8. using namespace std;
    9. const int N = 1e5 + 10;
    10. int a[N], b[N];
    11. //简化成两种情况即可:
    12. //1.存在一堆石头比剩下的几堆加起来都要多,这样T先手就可以一直取最多的那堆,直到赢
    13. //2.全部石头加一起为奇数,T赢,偶数,T输
    14. int main()
    15. {
    16. int t; cin >> t;
    17. while (t--)
    18. {
    19. int n; cin >> n;
    20. for (int i = 1; i <= n; i++) cin >> a[i];
    21. sort(a + 1, a + n + 1);
    22. int sum = 0;
    23. for (int i = 1; i < n; i++) sum += a[i];
    24. if (a[n] > sum)
    25. {
    26. cout << "T" << endl;
    27. continue;
    28. }
    29. else
    30. {
    31. sum += a[n];
    32. if (sum & 1) cout << "T" << endl;
    33. else cout << "HL" << endl;
    34. }
    35. }
    36. }

     

  • 相关阅读:
    AMS 新闻视频广告的云原生容器化之路
    R语言使用strsplit函数基于指定字符或者字符串分割字符串、使用sub函数进行字符串替换
    uniapp 小程序实现图片宽度100%、高度自适应的效果
    Docker 部署 Geoserver
    Spring Boot 多数据源配置
    使用C语言构建一个独立栈协程和共享栈协程的任务调度系统
    CF803B Distances to Zero(模拟+思维)
    深度学习笔记(2)——pytorch实现MNIST数据集分类(FNN、CNN、RNN、LSTM、GRU)
    POC&EXP编写—EXP编写实战(1)
    go通过pprof定位groutine泄漏
  • 原文地址:https://blog.csdn.net/GF0919/article/details/132745035