Codeforces Gym100500 Problem E. IBM Chill Zone (博弈)

Problem E. IBM Chill Zone

Program: zone.(c|cpp|java)
Input: zone.in
Balloon Color: Orange

A relaxing, fun way to unwind nightly with old and new friends at the ACM-ICPC World Finals is to stop by the IBM Chill Zone! A great way to participate in interactive games and interesting conversation with innovative IBMers and attendees from all over the world, the IBM Chill Zone is always a favorite for all. Many games can be found in the chill zone, including board game, human-size chess board, real-life angry birds, and stones game.
The stones game was invented by one of ICPC world finalists. It a 2-player game. It consists of a line of n stones and at each move a player should remove k consecutive stones, and if the player can not make any moves he loses, for example if we have n = 6, k = 2 (stones are represented by ’*’, and empty spaces by ’.’):
STARTING STATE * * * * * *
FIRST PLAYER * . . * * *
SECOND PLAYER * … . *
First player now has no valid moves, so he loses, but note that he did not play optimally here.
Given n, and k assume both players play optimally well, determine if the first player is losing or winning.

Input

The first line will be the number of test cases T. Each of the following T lines will contain 2 numbers n,
k.
1 ≤ T ≤ 100
1 ≤ n ≤ 50
1 ≤ k ≤ n

Output

For each test case print a single line containing:
Case_x:_y
x is the case number starting from 1.
y is either ’Winning’, or ’Losing’ without the quotes (winning if the first is winning, losing otherwise)
Replace underscores with spaces.

Examples

2
5 2
5 3
Case 1: Losing
Case 2: Winning

题意

给n个连续的石子,每次操作取走连续的k个,问先手胜负

题解

花了一晚上看sg函数。。终于AC了这道题,在这里讲一下SG函数,对于某个游戏状态,他的SG函数值是他所有后继状态的SG函数值中第一个没出现过的非负整数,对于一个由多个状态组成的游戏,例如本题n=5,k=2,取走两个之后的一种状态为(n=1,k=2)与(n=2,k=2)的组合,那么这个组合游戏的SG函数为SG(1,2)⊕SG(2,2)。对于状态x,若SG(x)>0,则当前状态为必胜态,若SG(x)<0,则为必败态,于是可以递归求解。附上AC代码。

#include <cstdio>
#include <cstring>

using namespace std;

int T;
int n,k;
int sg[55];
int SG(int x)
{
    if(sg[x]!=-1)
        return sg[x];
    int i,vis[55];
    memset(vis,0,sizeof vis);
    for(i=0;i<=(x-k)/2;i++)
        vis[SG(i)^SG(x-k-i)]=1;
    i=0;
    while(vis[i])
        i++;
    return sg[x]=i;
}
int main()
{
    scanf("%d",&T);
    for(int cas=1;cas<=T;cas++)
    {
        memset(sg,-1,sizeof sg);
        scanf("%d%d",&n,&k);
        printf("Case %d: ",cas);
        for(int i=0;i<k;i++)
            sg[i]=0;
        if(SG(n))
            printf("Winning\n");
        else
            printf("Losing\n");
    }
    return 0;
}
根据提供的引用内容,Codeforces Round 511 (Div. 1)是一个比赛的名称。然而,引用内容中没有提供与这个比赛相关的具体信息或问题。因此,我无法回答关于Codeforces Round 511 (Div. 1)的问题。如果您有关于这个比赛的具体问题,请提供更多的信息,我将尽力回答。 #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Codeforces Round 867 (Div. 3)(A题到E题)](https://blog.csdn.net/wdgkd/article/details/130370975)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值