zoukankan      html  css  js  c++  java
  • [CF1396B] Stoned Game

    [CF1396B] Stoned Game - 博弈

    Description

    有 N 堆石子,第 i 堆有 ai 个,两者轮流取其中一个石子。但不能取上次对手取过的那一堆。判断胜负。

    Solution

    某一堆比其他堆加起来还多,那么先手必胜

    否则,那么大家一定不希望上面这种情况出现,因此每次都会去取最多的那一堆,这样每个石子都会被取走,并且上面的条件不会被触发,因此判断奇偶性即可

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    signed main()
    {
        ios::sync_with_stdio(false);
        int t;
        cin >> t;
        while (t--)
        {
            int n;
            cin >> n;
            vector<int> a(n);
            for (int i = 0; i < n; i++)
                cin >> a[i];
            sort(a.begin(), a.end());
            reverse(a.begin(), a.end());
            int sum = 0;
            for (int i = 1; i < n; i++)
                sum += a[i];
            if (a[0] > sum)
                cout << "T";
            else if ((a[0] + sum) & 1)
                cout << "T";
            else
                cout << "HL";
            cout << endl;
        }
    }
    
  • 相关阅读:
    LeetCode 169. Majority Element
    Object-c block块
    Object-c动态特性
    Object-c基础(2)
    Object-c基础
    LeetCode171:Excel Sheet Column Number
    LeetCode242:Valid Anagram
    LeetCood8:String to Integer
    理解qsort 中的 cmp
    google goble cache
  • 原文地址:https://www.cnblogs.com/mollnn/p/14423440.html
Copyright © 2011-2022 走看看