• 上海五校赛 丢史蒂芬妮


    丢史蒂芬妮

    发布时间: 2017年7月9日 18:17   最后更新: 2017年7月9日 21:05   时间限制: 1000ms   内存限制: 128M

    有一天,空和白很无聊,决定玩盛大游戏,考虑到两个人玩,他们随便掏了一个游戏出来:在一个n 的棋盘上,首先把史蒂芬妮·多拉放在左上角(1,1 的位置。每次一个人可以将她往下,往右,往右下丢一格。当前回合,谁不能丢史蒂芬妮,谁就输了。(注意,不可以把活人丢出棋盘啦!)游戏总是空先手。

    白说,这是一个垃圾游戏!我们每次把史蒂芬妮丢素数个位置吧!(换句话说,每次丢 或…格)空答应了。

    我们都知道,空和白都很聪明,不管哪方存在一个可以必胜的最优策略,都会按照最优策略保证胜利。

    玩了一局,空已经知道了这个游戏的套路,现在他决定考考你,对于给定的 ,空是赢是输?如果空必胜,输出“Sora”(无引号);反之,输出“Shiro”(无引号)。

    第一行有一个T表示数组组数,1<=T<100000 
    从第二行开始,每行为棋盘大小, 分别表示行列。
    1=<n<=500 1=<m<=500 

    对于每组数据,按题目要求输出。

    复制
    4
    1 1
    2 2
    10 10
    30 30
    
    Shiro
    Shiro
    Shiro
    Sora
    分析:记忆化搜索即可;
    代码:
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <cstring>
    #include <string>
    #include <set>
    #include <bitset>
    #include <map>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <cassert>
    #include <ctime>
    #define rep(i,m,n) for(i=m;i<=(int)n;i++)
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    #define vi vector<int>
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define ll long long
    #define pi acos(-1.0)
    #define pii pair<int,int>
    #define sys system("pause")
    #define ls rt<<1
    #define rs rt<<1|1
    const int maxn=5e2+10;
    const int N=5e2+10;
    using namespace std;
    ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
    ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p%mod;p=p*p%mod;q>>=1;}return f;}
    int n,m,k,t,qu[maxn];
    bool dp[maxn][maxn],vis[maxn][maxn];
    bool dfs(int x,int y)
    {
        if(vis[x][y])return dp[x][y];
        vis[x][y]=true;
        for(int i=1;i<=qu[0];i++)
        {
            if(x-qu[i]>0)dp[x][y]|=(!dfs(x-qu[i],y));
            if(y-qu[i]>0)dp[x][y]|=(!dfs(x,y-qu[i]));
            if(x-qu[i]>0&&y-qu[i]>0)dp[x][y]|=(!dfs(x-qu[i],y-qu[i]));
        }
        return dp[x][y];
    }
    bool sushu(int x)
    {
        if(x==2)return true;
        else if(x%2==0)return false;
        for(int i=3;i*i<=x;i+=2)if(x%i==0)return false;
        return true;
    }
    void init()
    {
        int i,j;
        rep(i,2,maxn-10)if(sushu(i))qu[++qu[0]]=i;
        rep(i,1,maxn-10)rep(j,1,maxn-10)dfs(i,j);
    }
    int main()
    {
        int i,j;
        init();
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d%d",&n,&m);
            puts(dp[n][m]?"Sora":"Shiro");
        }
        return 0;
    }
  • 相关阅读:
    hdu1247 字典树或者hash
    hdu1247 字典树或者hash
    hdu1251 hash或者字典树
    hdu1251 hash或者字典树
    hdu4421 2-sat(枚举二进制每一位)
    hdu4421 2-sat(枚举二进制每一位)
    poj3648 2-sat
    poj3648 2-sat
    hdu 1814 字典序最小的2sat(暴力深搜)
    hdu 1814 字典序最小的2sat(暴力深搜)
  • 原文地址:https://www.cnblogs.com/dyzll/p/7144463.html
Copyright © 2020-2023  润新知