UVA11892 ENimEN —— 博弈
生活随笔
收集整理的這篇文章主要介紹了
UVA11892 ENimEN —— 博弈
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
?
題目鏈接:https://vjudge.net/problem/UVA-11892
?
?
題意:
兩人玩游戲,有n堆石子,每堆有ai塊石子,兩人輪流取,要求一次只能選擇一堆石子取任意塊。最后取完的獲勝。
?
題解:
由于一堆石子可以取任意塊,所以得出一個結論:當存在一堆石子數量大于1時,先手必勝。因為先手可以通過這些石子堆來調整自己的必勝狀態(或者說取消對手的必勝狀態)。但如果每堆石子只有一塊,那就每次只能取一塊,那結果顯而易見了。
?
代碼如下:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <vector> 6 #include <cmath> 7 #include <queue> 8 #include <stack> 9 #include <map> 10 #include <string> 11 #include <set> 12 using namespace std; 13 typedef long long LL; 14 const int INF = 2e9; 15 const LL LNF = 9e18; 16 const int MOD = 1e9+7; 17 const int MAXN = 20+10; 18 19 int main() 20 { 21 int T, n; 22 scanf("%d", &T); 23 while(T--) 24 { 25 bool win = false; 26 scanf("%d", &n); 27 for(int i = 1; i<=n; i++) 28 { 29 int a; 30 scanf("%d", &a); 31 if(a>1) win = true; 32 } 33 34 if(win || n%2) puts("poopi"); 35 else puts("piloop"); 36 } 37 } View Code?
轉載于:https://www.cnblogs.com/DOLFAMINGO/p/8349623.html
總結
以上是生活随笔為你收集整理的UVA11892 ENimEN —— 博弈的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 定位服务器的性能
- 下一篇: Lintcode189 First Mi