当前位置:网站首页>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 .
边栏推荐
- Redis builds clusters
- [CF Gym101196-I] Waif Until Dark 网络最大流
- 解决方案:智慧工地智能巡檢方案視頻監控系統
- [MySQL learning notes 29] trigger
- PHP Coding Standard
- ROS learning (IX): referencing custom message types in header files
- 继电反馈PID控制器参数自整定
- [nonlinear control theory]9_ A series of lectures on nonlinear control theory
- [factorial inverse], [linear inverse], [combinatorial counting] Niu Mei's mathematical problems
- [dictionary tree] [trie] p3879 [tjoi2010] reading comprehension
猜你喜欢
Generator Foundation
MEX有关的学习
. Net 6 learning notes: what is NET Core
[window] when the Microsoft Store is deleted locally, how to reinstall it in three steps
Ble of Jerry [chapter]
How to prevent Association in cross-border e-commerce multi account operations?
Compliance and efficiency, accelerate the digital transformation of pharmaceutical enterprises, and create a new document resource center for pharmaceutical enterprises
Esrally domestic installation and use pit avoidance Guide - the latest in the whole network
[redis] Introduction to NoSQL database and redis
Qualitative risk analysis of Oracle project management system
随机推荐
Cf1036c class numbers solution
Qualitative risk analysis of Oracle project management system
Luogu p4127 [ahoi2009] similar distribution problem solution
Simulation of holographic interferogram and phase reconstruction of Fourier transform based on MATLAB
数据治理:误区梳理篇
onie支持pice硬盘
Binary tree creation & traversal
Data governance: 3 characteristics, 4 transcendence and 3 28 principles of master data
23. Update data
合规、高效,加快药企数字化转型,全新打造药企文档资源中心
Inspiration from the recruitment of bioinformatics analysts in the Department of laboratory medicine, Zhujiang Hospital, Southern Medical University
datax自检报错 /datax/plugin/reader/._drdsreader/plugin.json]不存在
上线APS系统,破除物料采购计划与生产实际脱钩的难题
Wonderful use of TS type gymnastics string
[非线性控制理论]9_非线性控制理论串讲
Rust language - receive command line parameter instances
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
Machine learning - decision tree
When the Jericho development board is powered on, you can open the NRF app with your mobile phone [article]
Three treasures of leeks and Chinese men's football team