当前位置:网站首页>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 .
边栏推荐
- 洛谷P4127 [AHOI2009]同类分布 题解
- Pangolin Library: control panel, control components, shortcut key settings
- Ali's redis interview question is too difficult, isn't it? I was pressed on the ground and rubbed
- Ble of Jerry [chapter]
- 861. Score after flipping the matrix
- How to prevent Association in cross-border e-commerce multi account operations?
- 21. Delete data
- If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]
- [MySQL learning notes 30] lock (non tutorial)
- HTTP cache, forced cache, negotiated cache
猜你喜欢

Sharing of source code anti disclosure scheme under burning scenario

23. Update data

Opencv learning notes 9 -- background modeling + optical flow estimation

In the era of digital economy, how to ensure security?
![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]

Key value judgment in the cycle of TS type gymnastics, as keyword use
![Ble of Jerry [chapter]](/img/ed/32a5d045af8876d7b420ae9058534f.png)
Ble of Jerry [chapter]

Compliance and efficiency, accelerate the digital transformation of pharmaceutical enterprises, and create a new document resource center for pharmaceutical enterprises

Pangolin Library: control panel, control components, shortcut key settings

【Redis】NoSQL数据库和redis简介
随机推荐
TS 类型体操 之 循环中的键值判断,as 关键字使用
[cf gym101196-i] waif until dark network maximum flow
ROS learning (IX): referencing custom message types in header files
edge瀏覽器 路徑獲得
Comparison of usage scenarios and implementations of extensions, equal, and like in TS type Gymnastics
Ali's redis interview question is too difficult, isn't it? I was pressed on the ground and rubbed
Vit (vision transformer) principle and code elaboration
Ble of Jerry [chapter]
PHP Coding Standard
JMeter performance test steps practical tutorial
[KMP] template
Scala语言学习-08-抽象类
[redis] Introduction to NoSQL database and redis
1015 reversible primes (20 points) prime d-ary
Linked list interview questions (Graphic explanation)
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
octomap averageNodeColor函数说明
成为优秀的TS体操高手 之 TS 类型体操前置知识储备
Three no resumes in the software testing industry. What does the enterprise use to recruit you? Shichendahai's resume
[factorial inverse], [linear inverse], [combinatorial counting] Niu Mei's mathematical problems