Georgia and Bob POJ - 1704
Georgia and Bob 格魯吉亞和鮑勃
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 13319 Accepted: 4461
時間限制: 1000MS 內存限制: 10000K
提交總數: 13319 接受: 4461
Description 描述
Georgia and Bob decide to play a self-invented game.
格魯吉亞和鮑勃決定玩自己發明的游戲。
They draw a row of grids on paper, number the grids from left to right by 1, 2, 3, …, and place N chessmen on different grids, as shown in the following figure for example:
他們在紙上繪制一排網格,將網格從左到右依次為1,2,3,…,并將N個西洋棋棋子放在不同的網格上,如下圖所示:
Georgia and Bob move the chessmen in turn.
格魯吉亞和鮑勃依次移動西洋棋棋子。
Every time a player will choose a chessman, and move it to the left without going over any other chessmen or across the left edge.
每次玩家選擇一個棋子,并將其移動到左邊而不越過任何其他西洋棋棋子或橫跨左邊緣。
The player can freely choose number of steps the chessman moves, with the constraint that the chessman must be moved at least ONE step and one grid can at most contains ONE single chessman.
玩家可以自由選擇棋子移動的步數,其限制是棋子必須至少移動一步,一個網格最多可以包含一個棋子。
The player who cannot make a move loses the game.
無法移動的玩家將失去游戲。
Georgia always plays first since “Lady first”.
自“女士第一”以來,格魯吉亞總是首發。
Suppose that Georgia and Bob both do their best in the game, i.e., if one of them knows a way to win the game, he or she will be able to carry it out.
假設格魯吉亞和鮑勃都在比賽中盡了最大努力,也就是說,如果他們中的一個知道如何贏得比賽,那么他或她將能夠實現這一目標。
Given the initial positions of the n chessmen, can you predict who will finally win the game?
鑒于n個西洋棋棋子的初始位置,你能預測誰將最終贏得比賽嗎?
Input 輸入
The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases.
輸入的第一行包含單個整數T(1 <= T <= 20),即測試用例的數量。
Then T cases follow.
然后是T案例。
Each test case contains two lines.
每個測試用例包含兩行。
The first line consists of one integer N (1 <= N <= 1000), indicating the number of chessmen.
第一行由一個整數N(1 <= N <= 1000)組成,表示西洋棋棋子的數量。
The second line contains N different integers P1, P2 … Pn (1 <= Pi <= 10000), which are the initial positions of the n chessmen.
第二行包含N個不同的整數P1,P2 … Pn(1 <= Pi <= 10000),它們是n個西洋棋棋子的初始位置。
Output 輸出
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’.
對于每個測試案例,如果格魯吉亞將贏得比賽,則打印一行“格魯吉亞將獲勝”; 如果鮑勃將贏得比賽,“鮑勃會贏” 否則’不確定’。
Sample Input 樣例輸入
2
3
1 2 3
8
1 5 6 7 9 12 14 17
Sample Output 樣例輸出
Bob will win
Georgia will win
Code
#include <algorithm> #include <iostream> #include <cstring>using namespace std; string ans[1000]; int t, n, p[1000];string deal(int pInt[],int n) {std::sort(pInt, pInt + n);int result = 0;if ((n & 1) == 1)for (int i = 0; i < n; i += 2)result ^= (i == 0) ? (pInt[0] - 1) : (pInt[i] - pInt[i - 1] - 1);elsefor (int i = 1; i < n; i += 2)result ^= (pInt[i] - pInt[i - 1] - 1);if (result) return "Georgia will win";else return "Bob will win"; }int main() {cin >> t;for (int i = 0; i < t; ++i) {cin >> n;memset(p, 0, sizeof(p));for (int j = 0; j < n; ++j)cin >> p[j];ans[i] = deal(p,n);}for (int i = 0; i < t; ++i)cout << ans[i] << endl;return 0; } 與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的Georgia and Bob POJ - 1704的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode 292. Nim Ga
- 下一篇: 每周一题 —— 3n+1问题