链接:https://ac.nowcoder.com/acm/contest/338/I

来源:牛客网

题目描述

IG won the S championship and many people are excited, ii and gg are no exception. After watching the game, the two of them also want to play a game.

There is now an infinite chessboard with only one piece. Initially the pieces are placed at the (x, y) position (the board coordinates are counted from 0). They took turns to move the pieces. ii moves first.

There are three ways to move

  1. Move the piece to the left by one space (from (x, y) to (x-1, y)).
  2. Move the piece down one space (from (x, y) to (x, y-1)).
  3. Move the piece to the lower left by one space (from (x, y) to (x-1, y-1)).

It should be noted that the pieces cannot be removed from the board.

The first person who can not operate is judged negative (in other words, the first person who moves the piece to (0,0) wins).

Now give the initial coordinates x, y of the piece. Under the premise that both take the optimal strategy, please output the name of the winner (ii or gg).

输入描述:

The input contains only one line. Enter two integers x y to represent the initial coordinates of the piece. (0<=x, y<=1000)。

输出描述:

the winner’s name (ii or gg)。

示例

输入

1 1

输出

ii

输入

124 654

输出

gg

题意

ii和gg一起玩游戏,将一个石子放在棋盘(x,y)的位置,每次移动石子,必须把石子从(x,y)位置移动到(x,y-1)、(x-1,y)、(x-1,y-1)这三个位置中的其中一个位置,将石子移动到(0,0)点的人获胜,ii先移动

思路

一、博弈论

推出一部分的NP态,可以发现,当x%2==0x\%2==0x%2==0并且y%2==0y\%2==0y%2==0时,先手处于必败态

0 1 2 3 4 5
0 P N P N P N
1 N N N N N N
2 P N P N P N
3 N N N N N N
4 P N P N P N
5 N N N N N N

N代表先手必胜,P代表先手必败

二、DP

根据题意可以知道,(0,1),(1,1),(1,0)点为N状态。

可以得出递推关系:当前点如果为P状态,那么这个点的前一步对应的三个可能的点一定都为N状态

AC代码

//NP
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
if((n&1)||(m&1))
cout<<"ii"<<endl;
else
cout<<"gg"<<endl;
return 0;
}
//DP
#include<bits/stdc++.h>
#define ms(a,b) memset(a,b,sizeof(a))
const int maxn=1e3+10;
using namespace std;
int dp[maxn][maxn];
inline void init()
{
ms(dp,0);
dp[0][1]=dp[1][0]=dp[1][1]=1;
for(int i=1;i<maxn;i++)
{
for(int j=1;j<maxn;j++)
if(dp[i-1][j]&&dp[i][j-1]&&dp[i-1][j-1])
dp[i][j]=0;
else
dp[i][j]=1;
}
}
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
init();
int n,m;
cin>>n>>m;
if(dp[n][m])
cout<<"ii"<<endl;
else
cout<<"gg"<<endl;
return 0;
}

湖南大学第十四届ACM程序设计新生杯(重现赛)I:II play with GG(博弈论||DP)的更多相关文章

  1. 湖南大学第十四届ACM程序设计新生杯(重现赛)G a+b+c+d=? (16进制与LL范围)

    链接:https://ac.nowcoder.com/acm/contest/338/G来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言65536K6 ...

  2. 湖南大学第十四届ACM程序设计新生杯(重现赛)

    RANK  0 题数 0 期末复习没有参加,补几道喜欢的题. A: AFei Loves Magic  签到 思路 :不需考虑 碰撞 直接计算最终状态即可. #include<bits/stdc ...

  3. 湖南大学第十四届ACM程序设计新生杯 E.Easy Problem

    E.Easy Problem Description: Zghh likes number, but he doesn't like writing problem description. So h ...

  4. 湖南大学第十四届ACM程序设计新生杯 Dandan's lunch

    Dandan's lunch Description: As everyone knows, there are now n people participating in the competiti ...

  5. 福建工程学院第十四届ACM程序设计大赛 - E - 外传:小晋逃生记

    http://www.fjutacm.com/Contest.jsp?cid=705#P4 其实想清楚了就很简单,之前想了很多种方法,以为是二分什么的,看起来就像是一个单峰函数.但是发现直接暴力一波就 ...

  6. 福建工程学院第十四届ACM校赛M题题解 fwt进阶,手推三进制fwt

    第九集,结束亦是开始 题意: 大致意思就是给你n个3进制的数字,让你计算有多少对数字的哈夫曼距离等于i(0<=i<=2^m) 思路: 这个是一个防ak题,做法是要手推公式的fwt 大概就这 ...

  7. 湖南大学ACM程序设计新生杯大赛(同步赛)J - Piglet treasure hunt Series 2

    题目描述 Once there was a pig, which was very fond of treasure hunting. One day, when it woke up, it fou ...

  8. 湖南大学ACM程序设计新生杯大赛(同步赛)A - Array

    题目描述 Given an array A with length n  a[1],a[2],...,a[n] where a[i] (1<=i<=n) is positive integ ...

  9. 湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han

    题目描述 Small koala special love LiaoHan (of course is very handsome boys), one day she saw N (N<1e1 ...

随机推荐

  1. echarts 自适应方法 x和y x2和y2

    grid:{ x:65, y:20, x2:30, y2:30},

  2. 解决flask的502错误:upstream prematurely closed connection while reading response header from upstream

    我在使用 tiangolo/uwsgi-nginx-flask 部署flask应用的时候,经常运行一会儿就出现502错误,重新启动容器后,就恢复. 且经常会出现数据更新后,刷新结果不一致. docke ...

  3. 使用java命令出现Error: A JNI error has occurred, please check your installation and try again的错误

    运行Java程序,javac运行.java文件没有报错,但java运行的时候报错 ​​​ 仔细看一下报错 Exception in thread "main" java.lang. ...

  4. AStar算法()

    把网上的AStar算法的论述自己实现了一遍,一开始只是最基础的实现.当然,现在AStar算法已经演变出了各种优化的版本,这篇也会基于各种优化不断的更新. 如果对算法不熟悉可以看下Stanford的这篇 ...

  5. JS中的变量和数据类型

    所谓变量,就是里面存储的数据是可以改变的. 在使用变量之前,我们需要先声明变量.声明变量的关键字有var  let   const 在ES里面声明变量可以使用var,如下: //var 变量名 var ...

  6. 第一个HTML文档

    属性 和 值 1.作用 用来修饰元素 ex:让 p 标记的文本水平居中对齐 <p>Hello World</p> 2.语法      1.属性的声明必须位于开始标记里      ...

  7. PLL详解

    PLL  时钟是时序逻辑的灵魂. 在实际应用中,时钟信号在频率或者相位上通常并不满足直接使用的需求,而内部时序逻辑又只能对时钟信号进行整数倍的分频,并且不能保证产生新时钟信号的相位稳定性,所以需要用到 ...

  8. java基础知识—变量、数据类型和运算符

    1.变量:存储数据的一个基本单元.2.变量的声明和赋值: 1)声明并赋值;数据类型 变量名=值 例如:int prince=10; 2) 声明.赋值分为两步: 数据类型 变量名: 例如:int=pri ...

  9. Hyperledger Fabric 建立一个简单网络

    Building you first network 网络结构: 2个Orgnizations(每个Org包含2个peer节点)+1个solo ordering service 打开fabric-sa ...

  10. LAD 线性判别分析

    线性判别分析,简称LDA,是一种线性学习方法. 常用来降维,是一种有监督的降维方法,是基于最佳分类效果的降维方法. 核心思想 给定训练样本,带label,设法将样本投影到一条直线上,使得同类样例的投影 ...