HDU2516 取石子遊戲

2021-08-18 18:32:48 字數 805 閱讀 4909

problem description

1堆石子有n個,兩人輪流取.先取者第1次可以取任意多個,但不能全部取完.以後每次取的石子數不能超過上次取子數的2倍。取完者勝.先取者負輸出」second win」.先取者勝輸出」first win」.

input

輸入有多組.每組第1行是2<=n<2^31. n=0退出.

output

先取者負輸出」second win」. 先取者勝輸出」first win」.

參看sample output.

sample input

2 13

10000

0sample output

second win

second win

first win

題解斐波那契博弈,總之就是一波狂找規律,然後發現只要是斐波那契數先手就必敗???證明玄學,博主蒟蒻看不懂:

什麼齊肯多夫定理,什麼氣喘操作???這不就是找規律???

**

#include

using

namespace

std;

int n,top=1;

long

long f[100],maxn=1ll<<31;

void shai()

void ac()

printf("first win\n");

}int main()

hdu 2516 取石子遊戲

題目 hdu 2516 取石子遊戲 思路 fibonacci nim 列舉前幾項,發現2,3,5是必敗態,不能說明什麼。對於當前的狀態,第一次不能全部取完,其餘的每次取的時候,不能超過前者上一次的兩倍。對於當前狀態n,最多能取的是 ceil n 3 1 和 前一狀態取的的兩倍 兩者間的最小值。然後這...

hdu2516 取石子遊戲

題目大意 桌子上有若干個石子,兩人輪流取。每次必須取走乙個,但不得超過前面的那個人取的數的2倍。拿到最後乙個石子的贏得遊戲。首先,這是一道博弈題,毋庸置疑,找到必敗點,這道題就會有突破 1,2,3是不可否人的必敗點 對於4,先手先取走1個的話,後手就不能取3個,所以還剩下3個,3是必敗點,所以4就是...

hdu2516 取石子遊戲

思路 找規律。先寫個暴力程式,然後發現凡是斐波那契數,都是後手贏,否則先手贏。我也不知道為什麼。暴力程式在 中被注釋。include include include include include include include include include include include inc...