WC模拟(1.2) T3 取石子

这篇博客探讨了一种博弈问题——取石子游戏,分析了Alice和Bob之间的策略。通过结论分析,作者指出当石子堆的数量和分布满足特定条件时,一方能确保胜利。关键在于对石子堆数量取模后的四种情况分析,特别是涉及到堆数量的奇偶性和取石子的先后顺序。
摘要由CSDN通过智能技术生成

取石子

题目背景:

1.2 WC模拟T3

分析:结论分析

 

见到n堆石子 à 肯定是博弈啊

见到AliceBob玩游戏 à 肯定是博弈啊

看到无法操作者输 à 肯定是博弈啊

然后今天死成了智障······原来,三者合一还可以结论分析······

考虑,我们不妨设a < b,对于每堆石子,先对a + b取模,显然对于一堆石子如果它大于a + b一方取了,另一方可以直接跟上,所以相当于没有意义。那么取模之后可以分为4种情况。

(1) xi < a,对于答案没有影响

(2) a <= xi < b,只要存在一定是a胜利(b只能取其他的,a也取其他的,知道最后再用这一堆就可以了)

(3) b <= xi < 2 * a,相当于只能取一次,结合(4)分析奇偶性

(4) 2 * a <= xi,如果存在至少两个则a必胜(不管先手后手,一定能将其中至于取成(2)状态),如果存在一个且(3)为奇数个则a必胜(若a先手,直接变成(2),如果是后手,一共偶数堆,一人一堆取即可),存在1个且(3)为偶数个则先手胜(讨论先手的情况就可以清楚发现),如果不存在则(3)为奇数个先手必胜,(3)为偶数个后手必胜。

 

Source:

 

/*
	created by scarlyw
*/
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
#include <cctype>
#include <vector>
#include <set>
#include <queue>
#include <ctime>
#include <bitset>

inline char read() {
	static const int IN_LEN = 1024 * 1024;
	static char buf[IN_LEN], *s, *t;
	if (s == t) {
		t = (s = buf) + fread(buf, 1, IN_LEN, stdin);
		if (s == t) return -1;
	}
	return *s++;
}

///*
template<class T>
inline void R(T &x) {
	static char c;
	static bool iosig;
	for (c = read(), iosig = false; !isdigit(c); c = read()) {
		if (c == -1) return ;
		if (c == '-') iosig = true;	
	}
	for (x = 0; isdigit(c); c = read()) 
		x = ((x << 2) + x << 1) + (c ^ '0');
	if (iosig) x = -x;
}
//*/

const int OUT_LEN = 1024 * 1024;
char obuf[OUT_LEN], *oh = obuf;
inline void write_char(char c) {
	if (oh == obuf + OUT_LEN) fwrite(obuf, 1, OUT_LEN, stdout), oh = obuf;
	*oh++ = c;
}

template<class T>
inline void W(T x) {
	static int buf[30], cnt;
	if (x == 0) write_char('0');
	else {
		if (x < 0) write_char('-'), x = -x;
		for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 + 48;
		while (cnt) write_char(buf[cnt--]);
	}
}

inline void flush() {
	fwrite(obuf, 1, oh - obuf, stdout);
}

/*
template<class T>
inline void R(T &x) {
	static char c;
	static bool iosig;
	for (c = getchar(), iosig = false; !isdigit(c); c = getchar())
		if (c == '-') iosig = true;	
	for (x = 0; isdigit(c); c = getchar()) 
		x = ((x << 2) + x << 1) + (c ^ '0');
	if (iosig) x = -x;
}
//*/

int mod = 1000000000 + 7;
int n, a, b, x;
int cnt[4], ans[4];
bool flag;

inline int mod_pow(int a, int b) {
	int ans = 1;
	for (; b; b >>= 1, a = (long long)a * a % mod)
		if (b & 1) ans = (long long)ans * a % mod;
	return ans;
}

int main() {
	freopen("stone.in", "r", stdin);
	freopen("stone.out", "w", stdout);
	R(n), R(a), R(b);
	if (a > b) std::swap(a, b), flag = true;
	for (int i = 1; i <= n; ++i) {
		R(x), x %= (a + b);
		if (x < a) cnt[0]++;
		else if (x >= a && x < b) cnt[1]++;
		else if (x >= b && x < 2 * a) cnt[2]++;
		else cnt[3]++;
	}
	ans[0] = (long long)mod_pow(2, cnt[0]) * 
			((long long)(mod_pow(2, cnt[1]) - 1) * mod_pow(2, cnt[2] + cnt[3]) % mod
			 + (long long)mod_pow(2, cnt[2]) * (mod_pow(2, cnt[3]) - 1 - cnt[3]) % mod
			 + (long long)cnt[3] * (cnt[2] ? mod_pow(2, cnt[2] - 1) : 0) % mod) % mod;
	ans[1] = 0;
	ans[2] = (long long)mod_pow(2, cnt[0]) *  
			((long long)cnt[3] * (cnt[2] ? mod_pow(2, cnt[2] - 1) : 1) % mod
			 + (long long)(cnt[2] ? mod_pow(2, cnt[2] - 1) : 0)) % mod;
	ans[3] = (long long)mod_pow(2, cnt[0]) * 
			(long long)(cnt[2] ? mod_pow(2, cnt[2] - 1) : 1) % mod;
	if (flag) std::swap(ans[0], ans[1]);
	for (int i = 0; i < 4; ++i) 
		ans[i] = (ans[i] + mod) % mod, std::cout << ans[i] << " ";
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值