|
1 | 1 | [#0649-dota2-senate]
|
2 |
| -= 649. Dota2 Senate |
| 2 | += 649. Dota2 参议院 |
3 | 3 |
|
4 |
| -{leetcode}/problems/dota2-senate/[LeetCode - Dota2 Senate^] |
| 4 | +https://leetcode.cn/problems/dota2-senate/[LeetCode - 649. Dota2 参议院 ^] |
5 | 5 |
|
6 |
| -In the world of Dota2, there are two parties: the `Radiant` and the `Dire`. |
| 6 | +Dota2 的世界里有两个阵营:`Radiant`(天辉)和 `Dire`(夜魇) |
7 | 7 |
|
8 |
| -The Dota2 senate consists of senators coming from two parties. Now the senate wants to make a decision about a change in the Dota2 game. The voting for this change is a round-based procedure. In each round, each senator can exercise `one` of the two rights: |
| 8 | +Dota2 参议院由来自两派的参议员组成。现在参议院希望对一个 Dota2 游戏里的改变作出决定。他们以一个基于轮为过程的投票进行。在每一轮中,每一位参议员都可以行使两项权利中的 *一* 项: |
9 | 9 |
|
| 10 | +* *禁止一名参议员的权利*:参议员可以让另一位参议员在这一轮和随后的几轮中丧失 *所有的权利* 。 |
| 11 | +* *宣布胜利*:如果参议员发现有权利投票的参议员都是 *同一个阵营的*,他可以宣布胜利并决定在游戏中的有关变化。 |
10 | 12 |
|
11 |
| -. `Ban one senator's right`: |
| 13 | +给你一个字符串 `senate` 代表每个参议员的阵营。字母 `+'R'+` 和 |
| 14 | +`+'D'+`分别代表了 `Radiant`(天辉)和 `Dire`(夜魇)。然后,如果有 |
| 15 | +`n` 个参议员,给定字符串的大小将是 `n`。 |
12 | 16 |
|
| 17 | +以轮为基础的过程从给定顺序的第一个参议员开始到最后一个参议员结束。这一过程将持续到投票结束。所有失去权利的参议员将在过程中被跳过。 |
13 | 18 |
|
14 |
| - A senator can make another senator lose *all his rights* in this and all the following rounds. |
15 |
| -. `Announce the victory`: |
| 19 | +假设每一位参议员都足够聪明,会为自己的政党做出最好的策略,你需要预测哪一方最终会宣布胜利并在 |
| 20 | +Dota2 游戏中决定改变。输出应该是 `+"Radiant"+` 或 `+"Dire"+` 。 |
16 | 21 |
|
17 | 22 |
|
18 |
| - If this senator found the senators who still have rights to vote are all from *the same party*, he can announce the victory and make the decision about the change in the game. |
| 23 | +*示例 1:* |
19 | 24 |
|
| 25 | +.... |
| 26 | +输入:senate = "RD" |
| 27 | +输出:"Radiant" |
| 28 | +解释: |
| 29 | +第 1 轮时,第一个参议员来自 Radiant 阵营,他可以使用第一项权利让第二个参议员失去所有权利。 |
| 30 | +这一轮中,第二个参议员将会被跳过,因为他的权利被禁止了。 |
| 31 | +第 2 轮时,第一个参议员可以宣布胜利,因为他是唯一一个有投票权的人。 |
| 32 | +.... |
20 | 33 |
|
21 |
| - |
| 34 | +*示例 2:* |
22 | 35 |
|
23 |
| -Given a string representing each senator's party belonging. The character 'R' and 'D' represent the `Radiant` party and the `Dire` party respectively. Then if there are `n` senators, the size of the given string will be `n`. |
| 36 | +.... |
| 37 | +输入:senate = "RDD" |
| 38 | +输出:"Dire" |
| 39 | +解释: |
| 40 | +第 1 轮时,第一个来自 Radiant 阵营的参议员可以使用第一项权利禁止第二个参议员的权利。 |
| 41 | +这一轮中,第二个来自 Dire 阵营的参议员会将被跳过,因为他的权利被禁止了。 |
| 42 | +这一轮中,第三个来自 Dire 阵营的参议员可以使用他的第一项权利禁止第一个参议员的权利。 |
| 43 | +因此在第二轮只剩下第三个参议员拥有投票的权利,于是他可以宣布胜利 |
| 44 | +.... |
24 | 45 |
|
25 |
| -The round-based procedure starts from the first senator to the last senator in the given order. This procedure will last until the end of voting. All the senators who have lost their rights will be skipped during the procedure. |
| 46 | +*提示:* |
26 | 47 |
|
27 |
| -Suppose every senator is smart enough and will play the best strategy for his own party, you need to predict which party will finally announce the victory and make the change in the Dota2 game. The output should be `Radiant` or `Dire`. |
| 48 | +* `+n == senate.length+` |
| 49 | +* `1 \<= n \<= 10^4^` |
| 50 | +* `+senate[i]+` 为 `+'R'+` 或 `+'D'+` |
28 | 51 |
|
29 |
| -*Example 1:* |
30 | 52 |
|
31 |
| -[subs="verbatim,quotes,macros"] |
32 |
| ----- |
33 |
| -*Input:* "RD" |
34 |
| -*Output:* "Radiant" |
35 |
| -*Explanation:* The first senator comes from Radiant and he can just ban the next senator's right in the round 1. |
36 |
| -And the second senator can't exercise any rights any more since his right has been banned. |
37 |
| -And in the round 2, the first senator can just announce the victory since he is the only guy in the senate who can vote. |
38 |
| ----- |
| 53 | +== 思路分析 |
39 | 54 |
|
40 |
| - |
| 55 | +贪心算法。优先禁止最近的对方议员投票。不停循环,直到只留下一方议员。 |
41 | 56 |
|
42 |
| -*Example 2:* |
43 |
| - |
44 |
| -[subs="verbatim,quotes,macros"] |
| 57 | +[[src-0649]] |
| 58 | +[tabs] |
| 59 | +==== |
| 60 | +一刷:: |
| 61 | ++ |
| 62 | +-- |
| 63 | +[{java_src_attr}] |
45 | 64 | ----
|
46 |
| -*Input:* "RDD" |
47 |
| -*Output:* "Dire" |
48 |
| -*Explanation:* |
49 |
| -The first senator comes from Radiant and he can just ban the next senator's right in the round 1. |
50 |
| -And the second senator can't exercise any rights anymore since his right has been banned. |
51 |
| -And the third senator comes from Dire and he can ban the first senator's right in the round 1. |
52 |
| -And in the round 2, the third senator can just announce the victory since he is the only guy in the senate who can vote. |
| 65 | +include::{sourcedir}/_0649_Dota2Senate.java[tag=answer] |
53 | 66 | ----
|
| 67 | +-- |
54 | 68 |
|
55 |
| - |
56 |
| - |
57 |
| -*Note:* |
58 |
| - |
| 69 | +// 二刷:: |
| 70 | +// + |
| 71 | +// -- |
| 72 | +// [{java_src_attr}] |
| 73 | +// ---- |
| 74 | +// include::{sourcedir}/_0649_Dota2Senate_2.java[tag=answer] |
| 75 | +// ---- |
| 76 | +// -- |
| 77 | +==== |
59 | 78 |
|
60 |
| -. The length of the given string will in the range [1, 10,000]. |
61 | 79 |
|
| 80 | +== 参考资料 |
62 | 81 |
|
63 |
| - |
64 |
| - |
65 |
| - |
66 |
| - |
67 |
| -[[src-0649]] |
68 |
| -[{java_src_attr}] |
69 |
| ----- |
70 |
| -include::{sourcedir}/_0649_Dota2Senate.java[tag=answer] |
71 |
| ----- |
72 | 82 |
|
0 commit comments