HDU_1847_基础博弈sg函数

Good Luck in CET-4 Everybody!

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8715    Accepted Submission(s):
5643

Problem Description

大学英语四级考试就要来临了,你是不是在紧张的复习?也许紧张得连短学期的ACM都没工夫练习了,反正我知道的Kiki和Cici都是如此。当然,作为在考场浸润了十几载的当代大学生,Kiki和Cici更懂得考前的放松,所谓“张弛有道”就是这个意思。这不,Kiki和Cici在每天晚上休息之前都要玩一会儿扑克牌以放松神经。
“升级”?“双扣”?“红五”?还是“斗地主”?
当然都不是!那多俗啊~
作为计算机学院的学生,Kiki和Cici打牌的时候可没忘记专业,她们打牌的规则是这样的:
1、  总共n张牌;
2、  双方轮流抓牌;
3、  每人每次抓牌的个数只能是2的幂次(即:1,2,4,8,16…)
4、  抓完牌,胜负结果也出来了:最后抓完牌的人为胜者;
假设Kiki和Cici都是足够聪明(其实不用假设,哪有不聪明的学生~),并且每次都是Kiki先抓牌,请问谁能赢呢?
当然,打牌无论谁赢都问题不大,重要的是马上到来的CET-4能有好的状态。

Good
luck in CET-4 everybody!

Input

输入数据包含多个测试用例,每个测试用例占一行,包含一个整数n(1<=n<=1000)。

Output

如果Kiki能赢的话,请输出“Kiki”,否则请输出“Cici”,每个实例的输出占一行。

Sample Input

1

3

Sample Output

Kiki

Cici

拿石子游戏。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int S[10];
int cnts=0;
void getSS()
{

    for(int i=1;i<=1000;i*=2)
        S[cnts++]=i;
}

int sg[1005];
void getSg()
{
    int vis[1005],i,j;
    memset(sg,0,sizeof(sg));
    for(i=1;i<1005;i++)
    {
        memset(vis,0,sizeof(vis));
        for(j=0;j<cnts;j++)
            if(i-S[j]>=0)
                vis[sg[i-S[j]]]=1;
        for(j=0;j<1005;j++)
            if(vis[j]==0)
                break;
        sg[i]=j;
    }
}

int main()
{
    getSS();
    getSg();
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        if(sg[n]>0)
            printf("Kiki\n");
        else
            printf("Cici\n");
    }
    return 0;
}
时间: 2024-07-31 05:58:52

HDU_1847_基础博弈sg函数的相关文章

UVA 10561 - Treblecross(博弈SG函数)

UVA 10561 - Treblecross 题目链接 题意:给定一个串,上面有'X'和'.',可以在'.'的位置放X,谁先放出3个'X'就赢了,求先手必胜的策略 思路:SG函数,每个串要是上面有一个X,周围的4个位置就是禁区了(放下去必败),所以可以以X分为几个子游戏去求SG函数的异或和进行判断,至于求策略,就是枚举每个位置就可以了 代码: #include <stdio.h> #include <string.h> #include <algorithm> usi

hdu 3032(博弈sg函数)

题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办法求得sg的规律. 通过打表找规律可以得到如下规律:if(x%4==0) sg[x]=x-1; if(x%4==1||x%4==2) sg[x]=x; if(x%4==3) sg[x] = x+1. 打表代码: #include<iostream> #include<cstdio> #

UVA 11534 - Say Goodbye to Tic-Tac-Toe(博弈sg函数)

UVA 11534 - Say Goodbye to Tic-Tac-Toe 题目链接 题意:给定一个序列,轮流放XO,要求不能有连续的XX或OO,最后一个放的人赢,问谁赢 思路:sg函数,每一段...看成一个子游戏,利用记忆化求sg值,记忆化的状态要记录下左边和右边是X还是O即可 代码: #include <stdio.h> #include <string.h> const int N = 105; int t, sg[3][3][N]; char str[N]; int ge

HDOJ 5724 博弈SG函数

链接: http://blog.csdn.net/tc_to_top/article/details/51958964 题意: n行20列的棋盘,对于每行,如果当前棋子右边没棋子,那可以直接放到右边,如果有就跳过放到其后面的第一个空位子,A先操作,最后谁无法操作则输,给定每行棋子状态,问先手是否必胜 题解: 组合博弈问题,直接sg函数,因为列只有20,可以状压搞,枚举每个状态,找到该状态下可行的操作然后标记 代码: 31 int sg[1 << 21]; 32 int vis[21]; 33

(转)博弈 SG函数

此文为以下博客做的摘要: https://blog.csdn.net/strangedbly/article/details/51137432 ---------------------------------------------------------------------------------------- 1.定义P-position和N-positon P表示Previous,N表示Next. 即上一个移动的人有必胜策略的局面是P-position,"先手必败"或&qu

Marbles(博弈SG函数)

Marbles Gym - 101908B Using marbles as a currency didn't go so well in Cubic?nia. In an attempt to make it up to his friends after stealing their marbles, the Emperor decided to invite them to a game night in his palace. Of course, the game uses marb

[hdu-5795]A Simple Nim 博弈 尼姆博弈 SG函数打表找规律

[题目]题目链接 Two players take turns picking candies from n heaps,the player who picks the last one will win the game.On each turn they can pick any number of candies which come from the same heap(picking no candy is not allowed).To make the game more int

Light OJ 1296 - Again Stone Game (博弈sg函数递推)

F - Again Stone Game Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description Alice and Bob are playing a stone game. Initially there are n piles of stones and each pile contains some stone. Alice stars the

Light OJ 1199 - Partitioning Game (博弈sg函数)

D - Partitioning Game Time Limit:4000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description Alice and Bob are playing a strange game. The rules of the game are: Initially there are n piles. A pile is formed by some cell