当前位置:网站首页>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 .
边栏推荐
- Scala语言学习-08-抽象类
- Esrally domestic installation and use pit avoidance Guide - the latest in the whole network
- How to delete all the words before or after a symbol in word
- Ble of Jerry [chapter]
- After the hot update of uniapp, "mismatched versions may cause application exceptions" causes and Solutions
- [factorial inverse], [linear inverse], [combinatorial counting] Niu Mei's mathematical problems
- MEX有关的学习
- 861. Score after flipping the matrix
- 洛谷P4127 [AHOI2009]同类分布 题解
- TS 体操 &(交叉运算) 和 接口的继承的区别
猜你喜欢

opencv学习笔记八--答题卡识别
![If Jerry needs to send a large package, he needs to modify the MTU on the mobile terminal [article]](/img/57/12a97ab3d2dabfaf06bbe1788450cf.png)
If Jerry needs to send a large package, he needs to modify the MTU on the mobile terminal [article]
![If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]](/img/d6/92ad1c6f84415de6ab0dfd16cd6073.png)
If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]

Leecode-c language implementation -15 Sum of three ----- ideas to be improved

Force buckle day31

Google may return to the Chinese market after the Spring Festival.

Linked list interview questions (Graphic explanation)

Inspiration from the recruitment of bioinformatics analysts in the Department of laboratory medicine, Zhujiang Hospital, Southern Medical University

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

QT color is converted to string and uint
随机推荐
P3047 [usaco12feb]nearby cows g (tree DP)
Iterator Foundation
How to prevent Association in cross-border e-commerce multi account operations?
Opencv learning notes 9 -- background modeling + optical flow estimation
Mex related learning
Data governance: data quality
Jerry's general penetration test - do data transmission with app Communication [article]
CF1036C Classy Numbers 题解
Jerry's ad series MIDI function description [chapter]
TS类型体操 之 字符串的妙用
Scala语言学习-08-抽象类
23. Update data
Database addition, deletion, modification and query
HTTP cache, forced cache, negotiated cache
How to estimate the number of threads
Ble of Jerry [chapter]
Redis builds clusters
Notes on software development
Position() function in XPath uses
Type of data in energy dashboard