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专业在读,热爱编程。
    专业之外,喜欢阅读,尤爱哲学、金庸、马尔克斯。
  • 相关阅读:
    visual sudio开发工具使用小技巧
    JS去除右边的逗号
    下拉标题
    sp_addextendedproperty
    触发器的使用
    缺失一个正数
    组合总和 去重
    拖动 Drag
    n皇后问题
    括号生成
  • 原文地址:https://www.cnblogs.com/jmhwsrr/p/14122655.html
Copyright © 2011-2022 走看看