Georgia and Bob - POJ 1704 - Virtual Judge
由题意,棋子只能往左移动,而且棋子不能跳过棋子移动,每次至少移动一下,最多在一个范围内移动到前一个棋子的后面,这就可以考虑到Nim博弈的变形,Nim博弈是N堆石子每次从某堆石子中取任意个,优先取光所有石头的人获胜,这可以联想到两个棋子之间就相当于每一堆的石头,如果有奇数个棋子,那就把第一个棋子的坐标和0点看成一堆石子,就把每个区间的石头数量进行相互异或,非零先手赢,零后手赢
AC代码:
#pragma GCC optimize(2) #pragma GCC optimize(3) //#pragma GCC optimize("Ofast") #include <iostream> #include <queue> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <cstring> #include <string> #include <cctype> #include <map> #include <vector> #include <deque> #include <set> #include <stack> #include <numeric> #include <iomanip> #include <functional> using namespace std; #define lowbit(x) ((x) & -(x)) #define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); #define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef vector<int> vi; typedef vector<long long> vll; typedef vector<char> vc; template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template<class T> T power(T a, int b) { T res = 1; for (; b; b >>= 1, a = a * a) { if (b & 1) { res = res * a; } } return res; } template <typename T> inline void read(T& x) { x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); } x *= f; } /* Tips: 1.int? long long? 2.don't submit wrong answer 3.figure out logic first, then start writing please 4.know about the range 5.check if you have to input t or not 6.modulo of negative numbers is not a%b, it is a%b + abs(b) */ const int INF = 0x3f3f3f3f; const int mod = 1000000007; const double PI = acos(-1.0); void solve() { int n; cin >> n; vector<int> a(n + 10); for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a.begin() + 1, a.begin() + 1 + n); int ans = 0; for (int i = n; i > 0; i -= 2) { ans ^= a[i] - a[i - 1] - 1; } if (ans) { cout << "Georgia will win" << endl; } else { cout << "Bob will win" << endl; } } int main() { //IOS1; IOS2; int __t = 1; cin >> __t; for (int _t = 1; _t <= __t; _t++) { solve(); } return 0; } /* */
Georgia and Bob POJ1704(Nim博弈变形)
最新推荐文章于 2024-02-02 22:30:48 发布