洛谷 #2197. Nim遊戲
題意
有n堆石子,每人必須從任意一堆石子取任意多的石子(/not = 0),不能行動者輸
題解
SG函式
可以發現,對於第i堆石子a[i],可以達到0 ~ a[i] - 1這n個狀態,故SG(a[i]) = a[i](SG值從0開始)
然後用SG定理,求亦或和確定勝負
除錯記錄
無
#include <cstdio>
using namespace std;
int T, n;
int main(){
scanf("%d", &T);
while (T--){
scanf("%d", &n);
int ans = 0;
for (int x, i = 1; i <= n; i++){
scanf("%d", &x);
ans ^= x;
}
if (ans) printf("Yes\n");
else printf("No\n");
}
return 0;
}
相關推薦
洛谷.2197.nim遊戲(博弈論 Nim)
博弈 problem main pan fine 不能 cpp tro 博弈論 題目鏈接 後手必勝(先手必敗,P-position)當且僅當n堆石子數異或和為0。 首先0一定是P-position, 假設a1^a2^a3^...^an=K 若K!=0,則一定可以找到一個ai
洛谷 #2197. Nim遊戲
題意 有n堆石子,每人必須從任意一堆石子取任意多的石子(/not = 0),不能行動者輸 題解 SG函式 可以發現,對於第i堆石子a[i],可以達到0 ~ a[i] - 1這n個狀態,故SG(a[i]) = a[i](SG值從0開始) 然後用SG定理,求亦或和確定勝負
洛谷 P2197 nim遊戲
get new DG 這樣的 scanf -c nim遊戲 PE -m 洛谷 P2197 nim遊戲 題目描述 甲,乙兩個人玩Nim取石子遊戲。 nim遊戲的規則是這樣的:地上有n堆石子(每堆石子數
洛谷 1199三國遊戲
都沒有 永遠 main 深入 hang 文件名 code 中一 三國 題目描述 小涵很喜歡電腦遊戲,這些天他正在玩一個叫做《三國》的遊戲。 在遊戲中,小涵和計算機各執一方,組建各自的軍隊進行對戰。遊戲中共有 N 位武將(N為偶數且不小於 4),任意兩個武將之間有一個“默契值
洛谷P1199 三國遊戲 博弈論 數學
include 博弈 pan cst ++ for 個數 sin style 洛谷P1199 三國遊戲博弈論 數學 這道題 其實 人是必勝的 能取到的最大值 為 每行第二大值中的最大值 為什麽呢 假使第一次我們取到了我們心中的那個答案的所在行 那麽接著電腦會
洛谷 P1057 傳球遊戲 題解
輸入 ron 轉移 ring printf 序列 www. algo == 此文為博主原創題解,轉載時請通知博主,並把原文鏈接放在正文醒目位置。 題目鏈接:https://www.luogu.org/problem/show?pid=1057 題目描述 上體育課的
洛谷P1070 道路遊戲
cstring splay 電腦遊戲 說明 code display 擔心 技術分享 art P1070 道路遊戲 題目描述 小新正在玩一個簡單的電腦遊戲。 遊戲中有一條環形馬路,馬路上有 n 個機器人工廠,兩個相鄰機器人工廠之間由一小
洛谷P2670 掃雷遊戲
phi font 字符 clas 文件包含 遊戲 class size 一個 題目描述 掃雷遊戲是一款十分經典的單機小遊戲。在n行m列的雷區中有一些格子含有地雷(稱之為地雷格),其他格子不含地雷(稱之為非地雷格)。玩家翻開一個非地雷格時,該格將會出現一個數字——提示周圍格子
洛谷 P1965 轉圈遊戲 題解
數據 tps 方向 ase line long 一個 格式 org 此文為博主原創題解,轉載時請通知博主,並把原文鏈接放在正文醒目位置。 題目鏈接:https://www.luogu.org/problem/show?pid=1965 題目描述 n 個小夥伴(編號從
洛谷P1312 Mayan遊戲
noip lib pac .org ont day main clas 不能 P1312 Mayan遊戲 題目描述 Mayan puzzle是最近流行起來的一個遊戲。遊戲界面是一個 7 行5 列的棋盤,上面堆放著一些方塊,方塊不能懸空堆放
洛谷P1057 傳球遊戲
i++ ios namespace str iostream string ret int [1] f[i][j]表示第i輪j拿到球的方案數 轉移:f[i][j]=f[i-1][j+1] +f[i-1][j+-1].註意: 邊界f[0][1]=1; 還有當j=1或N時
洛谷 P1965 轉圈遊戲
https -1 文件名 pid http 表示 ostream for 簡單 此文為博主原創題解,轉載時請通知博主,並把原文鏈接放在正文醒目位置。 題目鏈接 https://www.luogu.org/problem/show?pid=1965 題目描述 n 個小夥伴(編
洛谷 P1080 國王遊戲
return orange algo argv 為什麽 整數 sizeof cnblogs urn 題目描述 恰逢 H 國國慶,國王邀請 n 位大臣來玩一個有獎遊戲。首先,他讓每個大臣在左、右手上面分別寫下一個整數,國王自己也在左、右手上各寫一個整數。然後,讓這 n 位大
●洛谷P2664 樹上遊戲
pan body www bsp problem 題解 log tps targe 題鏈: https://www.luogu.org/problemnew/show/P2664題解: 掃描線,線段樹維護區間覆蓋 https://www.luogu.org/blog/
洛谷 P1312 Mayan遊戲
兩個 left upload 文件名 顏色 tab fff 復制 bre P1312 Mayan遊戲 題目描述 Mayan puzzle是最近流行起來的一個遊戲。遊戲界面是一個 7 行5 列的棋盤,上面堆放著一些方塊,方塊不能懸空堆放,即
【刷題】洛谷 P2664 樹上遊戲
不同 ron clear 路徑 貢獻 utc ++i max long long 題目描述 lrb有一棵樹,樹的每個節點有個顏色。給一個長度為n的顏色序列,定義s(i,j) 為i 到j 的顏色數量。以及 現在他想讓你求出所有的sum[i] 輸入輸出格式 輸入格式: 第一行
洛谷1199三國遊戲
using n) lse 遊戲 new ref ace scan https 題目:https://www.luogu.org/problemnew/show/P1199 自己最大只能得到每一個武將的第二大配對。從中找一個最大的。 但是必勝,因為電腦得不到每一個武將的最大配
洛谷 P1070 道路遊戲 解題報告
消費機 完美 隊列優化 分享圖片 line std http 不出 ++ P1070 道路遊戲 題目描述 小新正在玩一個簡單的電腦遊戲。 遊戲中有一條環形馬路,馬路上有\(n\)個機器人工廠,兩個相鄰機器人工廠之間由一小段馬路連接。小新以某個機器人工廠為起點,按順時針順序依
洛谷1764 翻轉遊戲 - 枚舉 + 搜索
view radius 現在 輸入 pen 次數 ring 上下左右 ssi 題目描述 kkke在一個n*n的棋盤上進行一個翻轉遊戲。棋盤的每個格子上都放有一個棋子,每個棋子有2個面,一面是黑色的,另一面是白色的。初始的時候,棋盤上的棋子有的黑色向上,有的白色向上。現在k
洛谷P3825 [NOI2017]遊戲(2-SAT)
open while 怎麽 == sdi get style pre else 傳送門 果然圖論的題永遠建圖最麻煩……看著題解代碼的建圖過程真的很珂怕…… 先不考慮地圖$x$,那麽每一個地圖都只能用兩種賽車,