跳到正文

算法·理论

关于摩尔投币

SalN约 1 分钟
原文
文章信息与版本

文章信息

发布
2023年6月16日
收录
2026年2月1日
更新
2026年10月27日
篇幅
约 1 分钟

版本

  1. v2当前
  2. v1
C++
#include<bits/stdc++.h>

using namespace std;

int n, a, ans, cnt;

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i=1; i<=n; ++i) {
		cin >> a;
		if(cnt==0) ans=a;
		a==ans?cnt++:cnt--;
	}
	cout << ans;
	return 0;
}

link

玩一个诸侯争霸的游戏,每个人口出去干仗都能一对一跟对面同归于尽。

最后还有人活下来的国家就是胜利。

那就大混战呗,如果你超过人超过总人数的一半,最差所有人都联合起来对付你,你也能 win。

如果其他国家相互攻击,你也不亏,最后肯定你还是赢。

原文