↓ 跳过正文
  1. Posts/

codeforces #334 div 2 E. Lieges of Legendre

·387 字·1 分钟

http://codeforces.com/contest/604/problem/E 题意:有两个人做游戏,游戏规则如下: 有n堆石子,每次可以对一堆石子进行操作,如果当前石子是偶数,那么可以选择将这2*x个石子分成k堆石子数为x的石子堆,还有一种没有前提的操作是取走当前堆的一个石子,问先手赢还是后手赢,先手和后手都足够聪明的情况下。 思路:博弈论。。不会做。。第一次接触sg函数。。转载一篇题解: http://m.blog.csdn.net/blog/qq_24451605/50154973

代码实现
 1/* ***********************************************
 2Author :111qqz
 3Created Time :2015年12月22日 星期二 14时29分05秒
 4File Name :code/cf/#334/E.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,k,res;
34int pre[5]={0,1,0,1,2};
35
36int grundy( int a)
37{
38    if (k%2==0)
39    {
40	if (a==1) return 1;
41	if (a==2) return 2;
42	return (a%2)^1;
43    }
44    else
45    {
46	if (a<5) return pre[a];
47	if (a%2==1) return 0;
48	return (grundy(a/2)==1?2:1);
49    }
50}
51int main()
52{
53	#ifndef  ONLINE_JUDGE
54	freopen("code/in.txt","r",stdin);
55  #endif
56
57	cin>>n>>k;
58	for ( int i = 0 ; i < n; i++)
59	{
60	    int x;
61	    cin>>x;
62	    res ^= grundy(x);
63	}
64	if (res!=0)
65	{
66	    puts("Kevin");
67	}
68	else
69	{
70	    puts("Nicky");
71	}
72
73  #ifndef ONLINE_JUDGE
74  fclose(stdin);
75  #endif
76    return 0;
77}

相关文章

hdu 1849Rabbit and Grass(一维nim游戏,sg函数)

·1290 字·3 分钟
Rabbit and Grass # **Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3058 Accepted Submission(s): 2261 ** Problem Description 大学时光是浪漫的,女生是浪漫的,圣诞更是浪漫的,但是Rabbit和Grass这两个大学女生在今年的圣诞节却表现得一点都不浪漫:不去逛商场,不去逛公园,不去和AC男约会,两个人竟然猫在寝食下棋…… 说是下棋,其实只是一个简单的小游戏而已,游戏的规则是这样的: 1、棋盘包含1*n个方格,方格从左到右分别编号为0,1,2,…,n-1; 2、m个棋子放在棋盘的方格上,方格可以为空,也可以放多于一个的棋子; 3、双方轮流走棋; 4、每一步可以选择任意一个棋子向左移动到任意的位置(可以多个棋子位于同一个方格),当然,任何棋子不能超出棋盘边界; 5、如果所有的棋子都位于最左边(即编号为0的位置),则游戏结束,并且规定最后走棋的一方为胜者。

hdu 2149Public Sale(博弈论 巴什博奕)

·218 字·1 分钟
hdu 2149题目链接 题意&思路:巴什博奕,点m是n点。。。然后往前画即可。。。 代码实现 1/************************************************************************* 2 > File Name: code/hdu/2149.cpp 3 > Author: 111qqz 4 > Email: rkz2013@126.com 5 > Created Time: 2015年09月22日 星期二 20时18分02秒 6 ************************************************************************/ 7 8#include<iostream> 9#include<iomanip> 10#include<cstdio> 11#include<algorithm> 12#include<cmath> 13#include<cstring> 14#include<string> 15#include<map> 16#include<set> 17#include<queue> 18#include<vector> 19#include<stack> 20#include<cctype> 21#define y1 hust111qqz 22#define yn hez111qqz 23#define j1 cute111qqz 24#define ms(a,x) memset(a,x,sizeof(a)) 25#define lr dying111qqz 26using namespace std; 27#define For(i, n) for (int i=0;i<int(n);++i) 28typedef long long LL; 29typedef double DB; 30const int inf = 0x3f3f3f3f; 31int n,m; 32int main() 33{ 34 #ifndef ONLINE_JUDGE 35 freopen("in.txt","r",stdin); 36 #endif 37 while (scanf("%d %d",&m,&n)!=EOF) 38 { 39 if (m<n+1) 40 { 41 printf("%d",m); 42 for ( int i = m+1 ; i <= n; i++) 43 printf(" %d",i); 44 printf("\n"); 45 continue; 46 } 47 int tmp = m%(n+1); 48 if (tmp>0) 49 { 50 printf("%d\n",tmp); 51 } 52 else 53 { 54 puts("none"); 55 } 56 57 } 58 59 #ifndef ONLINE_JUDGE 60 fclose(stdin); 61 #endif 62 return 0; 63}

hdu 2188 悼念512汶川大地震遇难同胞——选拔志愿者 (巴什博奕)

·195 字·1 分钟
题目链接:hdu 2188题目链接 题意&思路:巴什博奕。。画n点p点。。。 代码实现 1/************************************************************************* 2 > File Name: code/hdu/2188.cpp 3 > Author: 111qqz 4 > Email: rkz2013@126.com 5 > Created Time: 2015年09月22日 星期二 20时08分08秒 6 ************************************************************************/ 7 8#include<iostream> 9#include<iomanip> 10#include<cstdio> 11#include<algorithm> 12#include<cmath> 13#include<cstring> 14#include<string> 15#include<map> 16#include<set> 17#include<queue> 18#include<vector> 19#include<stack> 20#include<cctype> 21#define y1 hust111qqz 22#define yn hez111qqz 23#define j1 cute111qqz 24#define ms(a,x) memset(a,x,sizeof(a)) 25#define lr dying111qqz 26using namespace std; 27#define For(i, n) for (int i=0;i<int(n);++i) 28typedef long long LL; 29typedef double DB; 30const int inf = 0x3f3f3f3f; 31void solve() 32{ 33 int n,m; 34 scanf("%d %d",&n,&m); 35 if (n%(m+1)!=0) 36 { 37 puts("Grass"); 38 } 39 else 40 { 41 puts("Rabbit"); 42 } 43} 44int main() 45{ 46 #ifndef ONLINE_JUDGE 47 freopen("in.txt","r",stdin); 48 #endif 49 int T; 50 cin>>T; 51 while (T--) 52 { 53 solve(); 54 } 55 #ifndef ONLINE_JUDGE 56 fclose(stdin); 57 #endif 58 return 0; 59}

acm博弈论

·4614 字·10 分钟
**序:**博弈是信息学和数学试题中常会出现的一种类型,算法灵活多变是其最大特点,而其中有一类试题更是完全无法用常见的博弈树来进行解答。 寻找必败态即为针对此类试题给出一种解题思路。