zoukankan      html  css  js  c++  java
  • 2020-12-11 Dota2参议院

    题目

    解题思路

    • 若当前所有议员都是天辉或夜魇的人,那么直接得出结果;
    • 否则,需要从对方还可以发言的议员中选择一位,将其禁掉。选择谁呢?应当优先选择这一轮中还能够发言的第一个对方议员,其次选择下一轮中第一个发言的议员。

    实现代码

    class Solution {
    public:
        string predictPartyVictory(string senate) {
            queue<int> radiant, dire;
            int n = senate.length();
            for (int i = 0; i < n; i++){
                if (senate[i] == 'R')
                    radiant.push(i);
                else
                    dire.push(i);
            }
    
            while (!radiant.empty() && !dire.empty()){
                if (radiant.front() < dire.front()){
                    radiant.push(n + radiant.front());
                } else {
                    dire.push(n + dire.front());
                }
                dire.pop();
                radiant.pop();
            }
            if (dire.empty()){
                return "Radiant";
            } else {
                return "Dire";
            }
        }
    };
    

    提交结果

    CS专业在读,热爱编程。
    专业之外,喜欢阅读,尤爱哲学、金庸、马尔克斯。
  • 相关阅读:
    刷题(十五)
    Pycharm按装
    Jmeter
    内存泄露部分检测工具
    Failed to resolve
    图片显示方向不对怎么办
    ScaleType属性
    RobotFramework
    LoadRunner
    Appium
  • 原文地址:https://www.cnblogs.com/jmhwsrr/p/14122655.html
Copyright © 2011-2022 走看看