hdu 1536 S-Nim sg函数

简介:

 最入门的sg,水题

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int c[102];
int sg[10005];
int k,n;
int get_sg(int now)
{
    if(~sg[now])return sg[now];
    int vis[102],i;
    memset(vis,0,sizeof(vis));
    for(i=0;i<k;i++)
    {
        if(now<c[i])continue;
        vis[get_sg(now-c[i])]=1;
    }
    for(i=0;vis[i]==1;i++);
    return sg[now]=i;
}
int main()
{
    while(~scanf("%d",&k)&&k)
    {
        int i,m;
        for(i=0;i<k;i++)scanf("%d",&c[i]);
        scanf("%d",&m);
        memset(sg,-1,sizeof(sg));
        sg[0]=0;
        int ans=0,t;
        while(m--)
        {
            ans=0;
            scanf("%d",&n);
            for(i=0;i<n;i++)
            {
                scanf("%d",&t);
                ans^=get_sg(t);
            }
            putchar(ans?'W':'L');
        }
        puts("");
    }
}


目录
相关文章
|
1月前
【力扣】292. Nim 游戏
【力扣】292. Nim 游戏
LeetCode 292. Nim Game
你和你的朋友,两个人一起玩 Nim游戏:桌子上有一堆石头,每次你们轮流拿掉 1 - 3 块石头。 拿掉最后一块石头的人就是获胜者。你作为先手。 你们是聪明人,每一步都是最优解。 编写一个函数,来判断你是否可以在给定石头数量的情况下赢得游戏。
60 0
LeetCode 292. Nim Game
|
算法 Java C#
LeetCode刷题292-简单-Nim游戏
LeetCode刷题292-简单-Nim游戏
199 0
LeetCode刷题292-简单-Nim游戏
|
决策智能
LeetCode之Nim Game
LeetCode之Nim Game
108 0
|
决策智能
[LeetCode]--292. Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone
1078 0
[LeetCode] Nim Game
Haha, an interesting problem. Just try to let your opponent start with a number that is an integer multiple of 4.
847 0
|
索引
Nim教程【十】
openarray类型 注意:openarray类型只能用于参数 固定大小的数组虽然性能不错,但过于呆板,使用取来不是很方便 对于一个方法来说,传入参数如果是一个数组,最好是不要限制数组的长度 也就是说,方法应该能够处理不同大小的数组 openarray类型就是为了满足这样的要求而设计...
1089 0
|
索引
Nim教程【九】
向关注这个系列的朋友们,道一声:久违了! 它并没有被我阉掉,他一定会得善终的,请各位不要灰心 Set集合类型 为了在特殊场景下提高程序的性能设置了Set类型,同时也是为了保证性能,所以Set只能容纳有序类型, Set类型可以被一个大括号实例化: var x = {},x就是一个空的set类型 还...
886 0
|
机器学习/深度学习 数据格式
Nim教程【七】
这是国内第一个关于Nim的系列教程 先说废话 很开心,在今天凌晨快一点多的时候拿到了 nim-lang.com;nim-lang.cn;nim-lang.net 这三个域名,到不是为了投资,准备用nim-lang.
1077 0