日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Georgia and Bob POJ - 1704 阶梯Nim

發(fā)布時間:2023/12/13 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Georgia and Bob POJ - 1704 阶梯Nim 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

$ \color{#0066ff}{ 題目描述 }$

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: 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?

\(\color{#0066ff}{輸入格式}\)

The first line of the input contains a single integer T (1 <= T <=20), the number of test cases. Then T cases follow. Each test case contains two lines. The first line consists of one integer N (1 <= N <= 1000), indicating the number of chessmen. The second line contains N different integers P1, P2 ... Pn (1 <= Pi <= 10000), which are the initial positions of the n chessmen.

\(\color{#0066ff}{輸出格式}\)

For each test case, prints a single line, "Georgia will win", if Georgiawill win the game; "Bob will win", if Bob will win the game; otherwise 'Not sure'.

\(\color{#0066ff}{輸入樣例}\)

2 3 1 2 3 8 1 5 6 7 9 12 14 17

\(\color{#0066ff}{輸出樣例}\)

Bob will win Georgia will win

\(\color{#0066ff}{數(shù)據(jù)范圍與提示}\)

none

\(\color{#0066ff}{題解}\)

移動一個棋子,與左邊的距離減小,與右邊的距離增大

可以抽象成幾堆石子,從一堆拿到另一堆,這就是階梯NIM了

#include <cctype> #include <cstdio> #include <algorithm>#define LL long long LL in() {char ch; LL x = 0, f = 1;while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));return x * f; } const int maxn = 2050; int a[maxn], b[maxn]; int main() {for(int T = in(); T --> 0;) {int n = in();for(int i = 1; i <= n; i++) a[i] = in();std::sort(a + 1, a + n + 1);int ans = 0;for(int i = n; i >= 1; i -= 2)ans = ans ^ (a[i] - a[i - 1] - 1) ; puts(!ans? "Bob will win" : "Georgia will win");}return 0; }

轉(zhuǎn)載于:https://www.cnblogs.com/olinr/p/10491697.html

總結(jié)

以上是生活随笔為你收集整理的Georgia and Bob POJ - 1704 阶梯Nim的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。