↓ Skip to main content
  1. Posts/

hdu 1517 A Multiplication Game (博弈论,将点的局势对应到段)

·675 words·2 mins
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

hdu 1517 题目链接

题意:初始为1,每次可以乘2..9中的一个数,最先达到或者超过n的人胜利。问谁有必赢策略。。

思路:一开始想用sg函数。。然而n太大(4e10)。。。绝对会超时。。。

所以可以更朴素得,去画n点和p点。。。我们可以发现。。。连续一段的局势是相同的。。。所以不能,也没必要找到每一个点对应的局势。

[n,+oo]是p点,那么[n/9,n-1]是n点,那么[n/9/2,n/9)又是p点。。。以此类推。。

这道题同时也告诉我们。。。没有什么方法是万能的。。。就算sg函数很神。。也有不能用的时候。。。所以掌握最本质的东西还是很重要的。。。

转载一段题解:


这道题如果用sg函数,利用点的局势做一定会超时,因为相同的局势能够形成连续的段,所以我们可以将局势对应到段来达到一定的优化:

首先题目中能够了解到必败态[n,+oo),那么可以由此推出必胜态

必胜态就是[n/9,n-1],也就是有一定有策略达到必败态

另一个必败态就是[n/9/2,n/9),之后就是一直循环这样的局势,找到了循环,我们可以固定一个点,固定区间的左端点比较易操作,也就是我们通过固定左端点找到1在必胜态区间,还是必败态区间.

代码实现
 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年07月20日 星期三 20时27分11秒
 4File Name :code/hdu/1517.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33LL n;
34int main()
35{
36	#ifndef  ONLINE_JUDGE
37	freopen("code/in.txt","r",stdin);
38  #endif
39
40
41	while (~scanf("%lld",&n))
42	{
43	    int cnt = 0 ;
44	    while (n>1)
45	    {
46		if (cnt%2==0) n = ceil(n*1.0/9.0);
47		else n = ceil(n*1.0/2.0);
48		cnt++;
49	    }
50	    if (cnt%2==1)
51		puts("Stan wins.");
52	    else puts("Ollie wins.");
53	}
54
55  #ifndef ONLINE_JUDGE
56  fclose(stdin);
57  #endif
58    return 0;
59}

Related

hdu 1848 Fibonacci again and again (sg函数)

·448 words·1 min
hdu 1848题目链接 题意:三堆石头,每次任选一堆取,取的石子数目必须是斐波那契数列中的数(1,2,3,5,8….)问先手是否有必赢策略。 思路:sg函数即可。。。。这次sg函数的优越性终于体现出来了。。。其他方法估计很难写吧。。

hdu 1850 Being a Good Boy in Spring Festival (nim游戏问必胜方案数,sg函数)

·422 words·1 min
hdu1850题目链接 题意:n堆石子。。每堆可以取任意多个。。。先取完的赢。。问先手能否赢。。能赢的话第一步有几种取法。。 思路:sg函数。。对于方案数,可以用nim游戏的结论。 以及。。sg函数。。如果走的步数是任意的。。也就是没有限制。。。那么sg[i] = i…此时也就退化成了一般的nim游戏。。。

hdu 1847 Good Luck in CET-4 Everybody! (巴什博奕,找规律||sg函数)

·635 words·2 mins
hdu1847题目链接 题意:n个石子,每次只能取2的幂次个。。。问先手是否有必赢策略。。。 思路:画n点p点。。。发现n为3的倍数的时候先手必输。。。否则先手必赢。。。 代码实现 1/* *********************************************** 2Author :111qqz 3Created Time :2016年07月20日 星期三 18时54分46秒 4File Name :code/hdu/1847.cpp 5************************************************ */ 6 7#include <cstdio> 8#include <cstring> 9#include <iostream> 10#include <algorithm> 11#include <vector> 12#include <queue> 13#include <set> 14#include <map> 15#include <string> 16#include <cmath> 17#include <cstdlib> 18#include <ctime> 19#define fst first 20#define sec second 21#define lson l,m,rt<<1 22#define rson m+1,r,rt<<1|1 23#define ms(a,x) memset(a,x,sizeof(a)) 24typedef long long LL; 25#define pi pair < int ,int > 26#define MP make_pair 27 28using namespace std; 29const double eps = 1E-8; 30const int dx4[4]={1,0,0,-1}; 31const int dy4[4]={0,-1,1,0}; 32const int inf = 0x3f3f3f3f; 33int n; 34int main() 35{ 36 #ifndef ONLINE_JUDGE 37 freopen("code/in.txt","r",stdin); 38 #endif 39 40 while (scanf("%d",&n)!=EOF) 41 { 42 if (n%3==0) 43 { 44 puts("Cici"); 45 } 46 else 47 { 48 puts("Kiki"); 49 } 50 } 51 52 #ifndef ONLINE_JUDGE 53 fclose(stdin); 54 #endif 55 return 0; 56} 也可以利用sg函数求解。。。 从这里我们可以看出,sg函数类似于母函数,本身并不是一类问题,而是一种求解问题的工具。

nim游戏以及证明过程

·748 words·2 mins
参考资料 (后面的证明写错了,差评,不要看,看图就好了) 1 1. 题目1:今有若干堆火柴,两人依次从中拿取,规定每次只能从一堆中取若干根, 可将一堆全取走,但不可不取,最后取完者为胜,求必胜的方法。

hdu 2147 kiki's game (巴什博奕)

·347 words·1 min
hdu 2147 题目链接 题意:一个n*m的方格,有一个棋子初始在右上角(1,m),每次可以将棋子向下或者向左或者向左下移动**一个格子,**不能移出边界,当无路可走的时候就输了,问谁存在必赢策略。