
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/scar_lyw/article/details/78960600
取石子
题目背景:
分析:结论分析
见到n堆石子 à 肯定是博弈啊
见到Alice和Bob玩游戏 à 肯定是博弈啊
看到无法操作者输 à 肯定是博弈啊
然后今天死成了智障······原来,三者合一还可以结论分析······
考虑,我们不妨设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; }
- 上一篇 WC模拟(1.2) T2 变量
- 下一篇 WC模拟(1.4) T1 序列