Dota2 Senate Dota2 参议院

Dota2 的世界里有两个阵营:Radiant(天辉)和 Dire(夜魇)

Dota2 参议院由来自两派的参议员组成。现在参议院希望对一个 Dota2 游戏里的改变作出决定。他们以一个基于轮为过程的投票进行。在每一轮中,每一位参议员都可以行使两项权利中的项:

  1. 禁止一名参议员的权利

    参议员可以让另一位参议员在这一轮和随后的几轮中丧失所有的权利


  2. 宣布胜利:如果参议员发现有权利投票的参议员都是同一个阵营的,他可以宣布胜利并决定在游戏中的有关变化。

给定一个字符串代表每个参议员的阵营。字母“R”和“D”分别代表了Radiant(天辉)和 Dire(夜魇)。然后,如果有 n 个参议员,给定字符串的大小将是n

以轮为基础的过程从给定顺序的第一个参议员开始到最后一个参议员结束。这一过程将持续到投票结束。所有失去权利的参议员将在过程中被跳过。

假设每一位参议员都足够聪明,会为自己的政党做出最好的策略,你需要预测哪一方最终会宣布胜利并在 Dota2 游戏中决定改变。输出应该是 Radiant 或 Dire

示例 1:

输入: "RD"
输出: "Radiant"
解释:  第一个参议员来自  Radiant 阵营并且他可以使用第一项权利让第二个参议员失去权力,因此第二个参议员将被跳过因为他没有任何权利。然后在第二轮的时候,第一个参议员可以宣布胜利,因为他是唯一一个有投票权的人

示例 2:

输入: "RDD"
输出: "Dire"
解释: 
第一轮中,第一个来自 Radiant 阵营的参议员可以使用第一项权利禁止第二个参议员的权利
第二个来自 Dire 阵营的参议员会被跳过因为他的权利被禁止
第三个来自 Dire 阵营的参议员可以使用他的第一项权利禁止第一个参议员的权利
因此在第二轮只剩下第三个参议员拥有投票的权利,于是他可以宣布胜利

注意:

  1. 给定字符串的长度在 [1, 10,000] 之间.

思路:这道题最直观的解法就是如果当前的元素是R,那么就把他右边的D删除(自身R再放入候选集中),如果当前的元素是D,就把他右边的R删除(自身D放入候选集中)。但是如果只是单纯删除会发生数组越界的情况,所以我们用两个数组q1和q2来保存R和D的下标,如果q1的队头比q2小,那么满足第一种情况,把q1的队头压入数组(原下标+senate.size()),否则把q2的队头压入数组。最后看哪个数组为空,返回不为空的那个数组对应的元素。

参考代码:

class Solution {
public:
    string predictPartyVictory(string senate) {
	queue<int> q1, q2;
	int n = senate.size();
	for (int i = 0; i < senate.size();i++) {
		if (senate[i] == 'R') q1.push(i);
		else q2.push(i);
	}
	while (q1.size() && q2.size()) {
		int r_index = q1.front(); q1.pop();
		int d_index = q2.front(); q2.pop();
		if (r_index < d_index) q1.push(r_index + n);
		else q2.push(d_index + n);
	}
	return q1.size() > q2.size() ? "Radiant" : "Dire";        
    }
};

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Caesar Assassinated: A Tragic Loss for Rome On March 15th, 44 BC, the Roman Republic was shaken to its core as its leader, Julius Caesar, was brutally assassinated by a group of senators. It was a tragic loss for Rome and its people. Caesar, a great military strategist and politician, had been a controversial figure in the Roman Senate. Many senators saw him as a threat to the Republic and its traditions, and some even feared that he would declare himself king. However, Caesar had always been a defender of the people and had done much to improve their lives. He had reformed the calendar, expanded the Roman Empire, and introduced many social and economic reforms. The assassination of Caesar was a cowardly act, carried out by a group of senators who were blinded by their own ambitions and prejudices. They had conspired against him for months, and when the opportunity presented itself, they struck. Caesar was stabbed 23 times, and he died on the steps of the Senate. The people of Rome were shocked and outraged by the assassination of their beloved leader. Many took to the streets in protest, and there were fears of a civil war. However, Caesar's loyal supporters, including Mark Antony and Octavian, managed to restore order and prevent further bloodshed. Caesar's death was a great loss for Rome. He had been a visionary leader who had brought peace and prosperity to the city. His legacy would live on, however, and his memory would inspire future generations of Romans to strive for greatness. In conclusion, the assassination of Julius Caesar was a tragic event that shook Rome to its core. It was a cowardly act carried out by ambitious men who were blinded by their own prejudices. However, Caesar's legacy would live on, and his memory would inspire future generations of Romans to strive for greatness.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值