• 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. }

     

  • 相关阅读:
    Java连接PostGreSql
    @RunWith注解找不到,怎么办?
    Logback的使用
    Django ORM深度游:探索多对一、一对一与多对多数据关系的奥秘与实践
    微服务使用UNI-APP开发手机APP流程及VUE前端注意事项
    小学生Python编程 ——飞机大战
    Redis高可用集群(哨兵、集群)
    基于JAVA图书馆借阅系统计算机毕业设计源码+数据库+lw文档+系统+部署
    Sora - 探索AI视频模型的无限可能
    【C++初阶】类和对象终极篇
  • 原文地址:https://blog.csdn.net/GF0919/article/details/132745035