• Stone Game, Why are you always there? HDU


    题意:给你n个数的集合,表示你每次取石子只能为集合里的数,然后给你一排石子,编号为1~n,每次你可以取相邻位置的连续石子(数量只能为集合里的数),注意石子的位置时不变的,比如把2拿走了,1和3还是不相邻的。问先手有没有机会赢。

    思路:如果我们取靠边的x个石子那么就是转移成sg[i-x],如果我们取中间的石子,就变成的不相邻的两排,也就是把单一的游戏拆成了两个,然后用sg就好了

    原文地址:https://blog.csdn.net/chy20142109/article/details/52145607

    #include <iostream>
    #include <cstdio>
    #include <sstream>
    #include <cstring>
    #include <map>
    #include <set>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #define MOD 2018
    #define LL long long
    #define ULL unsigned long long
    #define Pair pair<int, int>
    #define mem(a, b) memset(a, b, sizeof(a))
    #define _  ios_base::sync_with_stdio(0),cin.tie(0)
    //freopen("1.txt", "r", stdin);
    using namespace std;
    const int maxn = 10010, INF = 0x7fffffff;
    int sg[maxn], vis[maxn];
    int a[maxn];
    int main()
    {
        int n, m;
        while(cin>> n)
        {
            for(int i=0; i<n; i++)
                cin>> a[i];
            sort(a, a+n);
            sg[0] = 0;
            for(int i=1; i<=1000; i++)
            {
                mem(vis, 0);
                for(int j=0; j<n; j++)
                {
                    if(a[j] > i) break;
                    vis[sg[i-a[j]]] = 1;
                    if(i - a[j] > 1)
                    {
                        for(int k=1; k<= i-a[j]-1; k++)
                            vis[sg[k] ^ sg[i-a[j]-k]] = 1;
                    }
                }
                for(int j=0; ; j++)
                    if(!vis[j])
                    {
                        sg[i] = j;
                        break;
                    }
            }
            cin>> m;
            for(int i=0; i<m; i++)
            {
                int temp;
                cin>> temp;
                if(sg[temp])
                    cout<< 1 <<endl;
                else
                    cout<< 2 <<endl;
    
    
            }
    
    
        }
    
    
        return 0;
    }
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    nopcommerce 电商商城 ASP.NET 开源系统
    Android 圆形/圆角图片的方法
    5 shell命令之tr
    破茧成蝶2:和产品经理一起做需求分析
    android中单元測试中的断言assert的使用与扩展
    位置与地图(二)地图的使用以及标注地图
    找与一个数二进制表示1的个数相同的相邻的两个数
    Hook linux 网络封包
    使用ant自动编译、打包生成apk文件
    Analyzing the Analyzers 分析分析师 —— 数据科学部门如何建
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/9336171.html
Copyright © 2020-2023  润新知