当前位置:网站首页>649. Dota2 Senate
649. Dota2 Senate
2022-07-06 07:49:00 【Howi Zou】
Dota2 There are two camps in the world of :Radiant( Tianhui ) and Dire( Nightmares )
Dota2 The Senate is made up of senators from both sides . Now the Senate is hoping for a Dota2 Make decisions about changes in the game . They vote in a round based process . In each round , Every senator can exercise one of two rights :
Forbid the right of a Senator :
A senator can let another Senator lose all his rights in this and subsequent rounds .
Declare victory :
If senators find that all the senators who have the right to vote are in the same camp , He can declare victory and decide on changes in the game .
Given a string representing each Senator's camp . Letter “R” and “D” They represent Radiant( Tianhui ) and Dire( Nightmares ). then , If there is n A senator , The size of a given string will be n.
The round based process starts with the first senator in a given order and ends with the last senator . This process will continue until the end of the vote . All disenfranchised senators will be skipped in the process .
Suppose every senator is smart enough , Will make the best strategy for their party , You need to predict which side will eventually declare victory and be in Dota2 Decide to change... In the game . The output should be Radiant or Dire.
class Solution {
public String predictPartyVictory(String senate) {
Queue<Integer> R = new LinkedList<>();
Queue<Integer> D = new LinkedList<>();
for(int i = 0; i < senate.length(); i++){
if(senate.charAt(i) == 'R'){
R.add(i);
}else{
D.add(i);
}
}
while(!R.isEmpty() && !D.isEmpty()){
int r = R.poll();
int d = D.poll();
if(r < d){
R.add(r+senate.length());// This round is over , Tail insertion , Add to the next round (+senate.length())
}else{
D.add(d+senate.length());
}
}
return !R.isEmpty() ? "Radiant" : "Dire";
}
}
The core of this question is to kill the political enemy who is behind and closest to him , You can set up two queues , Let people from two different political parties i The team , Every time after cutting down the people of the other party , Line up and add the string length , Reentry team .
Final , The party whose queue is not empty wins .
边栏推荐
- Parameter self-tuning of relay feedback PID controller
- Simulation of Teman green interferometer based on MATLAB
- 成为优秀的TS体操高手 之 TS 类型体操前置知识储备
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- js對象獲取屬性的方法(.和[]方式)
- Simulation of holographic interferogram and phase reconstruction of Fourier transform based on MATLAB
- 解决方案:智慧工地智能巡檢方案視頻監控系統
- 洛谷P1836 数页码 题解
- Database addition, deletion, modification and query
- Ble of Jerry [chapter]
猜你喜欢
Ali's redis interview question is too difficult, isn't it? I was pressed on the ground and rubbed
[computer skills]
Solution: intelligent site intelligent inspection scheme video monitoring system
Do you really think binary search is easy
[MySQL learning notes 30] lock (non tutorial)
In the era of digital economy, how to ensure security?
解决方案:智慧工地智能巡检方案视频监控系统
Ble of Jerry [chapter]
Description of octomap averagenodecolor function
Risk planning and identification of Oracle project management system
随机推荐
Force buckle day31
Jerry's general penetration test - do data transmission with app Communication [article]
Solution: système de surveillance vidéo intelligent de patrouille sur le chantier
How to delete all the words before or after a symbol in word
珠海金山面试复盘
Basics of reptile - Scratch reptile
xpath中的position()函数使用
TS 类型体操 之 循环中的键值判断,as 关键字使用
leecode-C語言實現-15. 三數之和------思路待改進版
Mex related learning
datax自检报错 /datax/plugin/reader/._drdsreader/plugin.json]不存在
Simulation of Teman green interferometer based on MATLAB
洛谷P4127 [AHOI2009]同类分布 题解
Mise en œuvre du langage leecode - C - 15. Somme des trois chiffres - - - - - idées à améliorer
C # create database connection object SQLite database
数据治理:元数据管理篇
23. Update data
Opencv learning notes 8 -- answer sheet recognition
Position() function in XPath uses
Parameter self-tuning of relay feedback PID controller