Georgia and Bob POJ - 1704 階梯Nim

$ \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: img 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}{數據范圍與提示}\)

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;
}

轉載于:https://www.cnblogs.com/olinr/p/10491697.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/248400.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/248400.shtml
英文地址,請注明出處:http://en.pswp.cn/news/248400.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Tomcat總結

Tomcat調優原理&#xff1a; 1、增加最大連接數&#xff08;增大值避免隊列請求過多&#xff0c;導致響應緩慢&#xff09; 2、調整工作模式 Bio(BlockingI/O)&#xff1a;默認工作模式&#xff0c;阻塞式I/O操作&#xff0c;沒有任何優化技術處理&#xff0c;性能比較低。Nio(…

Android中寫文本文件的方法

下面是我在Android開發中&#xff0c;一個寫文本文件的方法&#xff0c;代碼如下&#xff1a; //將字符串寫入到文本文件中 public static void WriteTxtFile(String strcontent,String strFilePath) { //每次寫入時&#xff0c;都換行寫 String strConten…

前端筆記-jquery

jquery簡介 兼容性強,輕量級庫,js的框架,國外的大神寫好我們只要調用就好了,jquery可以把js寫的更加簡單 jquery使用 <script srcjquery-x.x.x.js></script> 引入文件就行了 jquery語法 $(selector).action() jquery選擇器 1.基本選擇器 $("*") $(&quo…

JVM的監控工具之jstack

參考博客&#xff1a;https://www.jianshu.com/p/213710fb9e40 jstack&#xff08;Stack Trace for Java&#xff09;命令用于生成虛擬機當前時刻的線程快照&#xff08;一般稱為threaddump或者javacore文件&#xff09;。線程快照就是當前虛擬機內每一條線程正在執行的方法堆棧…

liunx驅動----異步通知

查詢&#xff1a;消耗資源 中斷&#xff1a;read 一直要去讀poll &#xff1a;指定起始時間異步通知signal 測試程序include <stdio.h> include <signal.h>void my_signal(int signum) {static unsigned int cnt;printf("signum %d, %d timer\n",signum…

面試官: 用css實現android系統的loading動畫

源碼: github.com/any86/any-u… ios/android web常用的loading圖標有2種, 一種是ios的"菊花", 一種是android的"環". 今天我們用svg實現android的"環"動畫, 下節課實現ios的"菊花". 注意: gif幀數少的原因, 實際動畫效果是很平滑的.d…

2018-06-29 西游記主題Python入門示例嘗試-數據結構 5.1-5.1.2

(見前: 中文代碼示例視頻演示Python入門第五章 數據結構 仍然基于官方文檔, 歡迎建議(尤其是如何取材). 5. Data Structures - More on Lists 列表詳述 >>> 人物 [佛, 妖, 凡人, 菩薩, 妖, 凡人] >>> 人物.count(妖) 2 >>> 人物.count(圣人) 0 >…

Niginx 集群負載均衡策略

Niginx 集群負載均衡策略 所需物料 1.Nginx服務 步驟略 本人 nginx version: nginx/1.16.0 2.Java Servlet 測試項目 新建java web 項目&#xff0c;項目名稱為&#xff1a;tt import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annot…

C#循環給多個控件賦值

需要給 多個 文本框重新賦值 1 textBox1.Text"ss"; 2 3 textBox2.Text"ss"; 4 5 textBox999.Text"ss"; 6 7 textBox99999.Text"ss"; 這樣太麻煩&#xff0c;控件過多不方便寫 通過遍歷 一次性賦值&#xff0c;再多也不怕了 將所有T…

記號一次更換IBM X3650M4主板后RAID無法啟動的解決

https://wenku.baidu.com/view/9d503ef367ec102de2bd89d7.html 強烈感謝上面分享文檔的大俠&#xff01;&#xff01; 1、更換主板后&#xff0c;linux系統&#xff0c;無法加載引導。需要設置主板的啟動項 2、選擇boot manager&#xff0c;進到下面的畫面 3、選擇add boot opt…

關于REST API設計的一些小經驗

版權聲明&#xff1a;轉載時請以超鏈接形式標明文章原始出處和作者信息及本聲明http://phoenixtoday.blogbus.com/logs/45855234.html 最近小組里有一些關于REST API設計的討論&#xff0c;有些收獲&#xff0c;打算在這里寫一下。通常來講設計第一個版本的REST API并不難&…

1037 在霍格沃茨找零錢

題目傳送門&#xff1a;https://pintia.cn/problem-sets/994805260223102976/problems/994805284923359232 題解&#xff1a; #include<iostream> using namespace std;int main() {int Galleon1, Sickle1, Knut1, Galleon2, Sickle2, Knut2;char c;cin >> Galleon…

我對創業和管理的一些看法

創業&#xff0c;對于剛工作的人&#xff0c;會比較興奮&#xff0c;因為創業充滿想象力&#xff1b;對于工作幾年的人&#xff0c;會比較向往&#xff0c;因為壓抑得太久。其實&#xff0c;創業和就業一樣&#xff0c;只是實現自己人生價值的兩種方式&#xff0c;關鍵是心態問…

關于Anaconda的環境和包管理

Anaconda相對于原生python解釋器具有更好的包管理功能&#xff0c;它有一個env文件夾&#xff0c;里面包含所要管理的所有環境&#xff1b;日常操作時我們可能會使用pytorch、Tensorflow等多個環境&#xff0c;由于每個環境對Python的包的兼容性都不一樣&#xff0c;所以我們可…

WCF basicHttpBinding之Message Security Mode

原創地址&#xff1a;http://www.cnblogs.com/jfzhu/p/4067873.html 轉載請注明出處 前面的文章《WCF Security基本概念》介紹了WCF的security mode&#xff0c;簡單說Transport是transport級別上的加密&am…

戰略游戲

題目描述 Bob喜歡玩電腦游戲&#xff0c;特別是戰略游戲。但是他經常無法找到快速玩過游戲的辦法。現在他有個問題。 他要建立一個古城堡&#xff0c;城堡中的路形成一棵樹。他要在這棵樹的結點上放置最少數目的士兵&#xff0c;使得這些士兵能了望到所有的路。 注意&#xff0…

Vue語法學習第三課——計算屬性

模板內的表達式非常便利&#xff0c;但是設計它們的初衷是用于簡單運算的。在模板中放入太多的邏輯會讓模板過重且難以維護。對于任何復雜邏輯&#xff0c;都應當使用計算屬性。 <div id"example"><p>original message : "{{message}}"</p&…

云計算學習資料分享:type查看命令

type 查看命令類型&#xff0c;例如該命令是alias&#xff0c;還是內置命令&#xff0c;還是某個文件&#xff0c;還是關鍵字 哪種神仙&#xff1a;天上還是地上&#xff0c;還是水里游的 [roottianyun ~]# type ll ll is aliased to ls -l --colorauto [roottianyun ~]# type …

neo4j刪除所有節點

MATCH (n)OPTIONAL MATCH (n)-[r]-()DELETE n,r轉載于:https://www.cnblogs.com/luoganttcc/p/10525189.html

Hadoop RPC實例

本文發表于本人博客。 上次寫了個hadoop偽分布環境搭建的筆記了&#xff0c;今天來說下hadoop分布式構建的基礎RPC&#xff0c;這個RPC在提交Job任務的時候底層就是創建了RPC來實現遠程過程調用服務端。 我們首先可以通過Job的waitForCompletion(boolean verbose)方法來跟蹤代碼…