hdu 1536 S-Nim (简单sg函数)

题意:首先输入K 表示一个集合的大小  之后输入集合 表示对于这对石子只能去这个集合中的元素的个数

之后输入 一个m 表示接下来对于这个集合要进行m次询问

之后m行 每行输入一个n 表示有n个堆  每堆有n1个石子  问这一行所表示的状态是赢还是输 如果赢输入W否则L

思路:sg打表一下

#include <iostream>
#include <cstring>
using namespace std;
const int maxn=10008;

int f[maxn],n;//n代表集合元素的个数
int sg[maxn];
bool has[maxn];

void getsg()
{
    memset(sg,0,sizeof(sg));
    for(int i=1;i<=maxn;i++)
    {
        memset(has,false,sizeof(has));
        for(int j=1;j<=n;j++)
        {
            if(i>=f[j])
             has[sg[i-f[j]]]=true;
        }
        for(int j=0;j<=maxn;j++)
        {
            if(has[j]==false)
            {
                sg[i]=j;
                break;
            }
        }
    }
}

int main()
{
    while(cin>>n&&n)
    {
        string ou="";
        for(int i=1;i<=n;i++)
        cin>>f[i];
        getsg();
        int m;
        cin>>m;
        while(m--)
        {
            int t;
            int ans=0;
            cin>>t;
            for(int i=1;i<=t;i++)
            {
                int k;
                cin>>k;
                ans=ans^sg[k];
            }
            if(ans)
            ou+=‘W‘;
            else
            ou+=‘L‘;
        }
        cout<<ou<<endl;
    }
    return 0;
}
时间: 2024-11-05 15:17:04

hdu 1536 S-Nim (简单sg函数)的相关文章

HDU 3032 Nim or not Nim? (sg函数求解)

Nim or not Nim? Problem Description Nim is a two-player mathematic game of strategy in which players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provide

hdu 5795 A Simple Nim 博弈sg函数

A Simple Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description 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 an

hdu 1848 简单SG函数

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 Problem Description 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:F(1)=1;F(2)=2;F(n)=F(n-1)+F(n-2)(n>=3);所以,1,2,3,5,8,13……就是菲波那契数列.在HDOJ上有不少相关的题目,比如1005 Fibonacci again就是曾经的浙江省赛题.今天,又一个关于Fibonacc

HDU 2897-邂逅明下(sg函数)

邂逅明下 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 2897 Appoint description:  System Crawler  (2015-03-13) Description 当日遇到月,于是有了明.当我遇到了你,便成了侣. 那天,日月相会,我见到了你.而且,大地失去了光辉,你我是否成侣?这注定是个凄美的故事.(以上是废

BZOJ 1874: [BeiJing2009 WinterCamp]取石子游戏 [Nim游戏 SG函数]

小H和小Z正在玩一个取石子游戏. 取石子游戏的规则是这样的,每个人每次可以从一堆石子中取出若干个石子,每次取石子的个数有限制,谁不能取石子时就会输掉游戏. 小H先进行操作,他想问你他是否有必胜策略,如果有,第一步如何取石子. N≤10 Ai≤1000 裸SG函数啊 然而我连SG函数都不会求了,WA了一会儿之后照别人代码改发现vis公用了... #include <iostream> #include <cstdio> #include <cstring> #includ

HDU Nim or not Nim? (Nim,sg函数)

题意:给出几堆石子数量,每次可以取走一堆中任意数量的石头,也可以将一堆分成两堆,而不取.最后取走者胜. 思路:石子数量很大,不能直接算,sg打表找出规律:正常情况下a[i]=i,但是有例外的,就是i%4=0和i%4=3的sg值是交换了的,所以要算某个状态的sg值时,若模4为0,则进行自减,若模4为3则进行自加,这样就得到了sg值.最后再求全部异或和.若0,则先手输.否则先手胜. 1 #include <bits/stdc++.h> 2 using namespace std; 3 const

hdu3032 Nim or not Nim?(SG函数)

Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1710    Accepted Submission(s): 845 Problem Description Nim is a two-player mathematic game of strategy in which players take tur

HDU 1524 A Chess Game(SG函数)

Problem Description: Let's design a new chess game. There are N positions to hold M chesses in this game. Multiple chesses can be located in the same position. The positions are constituted as a topological graph, i.e. there are directed edges connec

hdu 3032 Nim or not Nim? sg函数

Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1056    Accepted Submission(s): 523 Problem Description Nim is a two-player mathematic game of strategy in which players take turn