NC51095. Georgia and Bob
描述
输入描述
The first line of the input contains a single integer T , the number of test cases. Then T cases follow. Each test case contains two lines. The first line consists of one integer N, indicating the number of chessmen. The second line contains N different integers, which are the initial positions of the n chessmen.
输出描述
For each test case, prints a single line, "Georgia will win", if Georgia will win the game; "Bob will win", if Bob will win the game; otherwise 'Not sure'.
示例1
输入:
2 3 1 2 3 8 1 5 6 7 9 12 14 17
输出:
Bob will win Georgia will win
C++14(g++5.4) 解法, 执行用时: 3ms, 内存消耗: 492K, 提交时间: 2019-11-02 22:06:19
#include <iostream> #include <algorithm> using namespace std; int main() { int t; cin >> t; while( t-- ) { int a[1005]; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } int ans = 0; sort(a,a+n); for (int i = n - 1; i >= 0; i-= 2) { if( i == 0 ) { if( a[i] != 1 ) ans ^= (a[i] - 1); } else ans ^= (a[i] - a[i-1] - 1); } if( ans == 0 ) cout << "Bob will win" << endl; else cout << "Georgia will win" << endl; } return 0; }
C++ 解法, 执行用时: 3ms, 内存消耗: 284K, 提交时间: 2021-08-08 11:40:05
#include <iostream> #include <algorithm> using namespace std; const int MAXN = 1e3 + 7; int a[MAXN]; int main() { int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); for(int i = 1;i <= n;++i) scanf("%d",&a[i]); sort(a + 1,a + n + 1); int ans = 0; for(int i = n;i > 0;i -= 2) ans ^= (a[i] - a[i - 1] - 1); if(ans) puts("Georgia will win"); else puts("Bob will win"); } return 0; }