链接: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. 漫谈hashcode

    概要 对于hashcode,相信很多朋友都不陌生,应为我们很多时候都需要用到这个,比如hashMap中就用到了,根据key的hash值来决定value存放的位置,之后来取得时候直接到指定的位置上那就行 ...

  2. 第4次作业 -- 基于Jenkins的持续集成

    Jenkins 配置使用心得 先在 https://jenkins.io/download/ 下载Jenkins 下载之后安装,在指定的地方找到了初始密码,安装了一些插件之后,Jenkins就可以使用 ...

  3. C# WebAPI分页实现分享

    第一次分享代码,不足或不对之处请指正.. 需求:微信端传递不同的参数调用WebAPI进行分页查询菜谱计划点评结果 思路:基于视图来查询,根据传递的不同参数拼接分页查询Sql来查询. 分页的sql如下 ...

  4. ecplise中设置字符编码

    ecplise 设置 1 ecplise编码格式 右键 在general-workspace- text file encoding 选择utf-8 2 jsp文件编码格式 web-jspfile-e ...

  5. 结对作业收获_core组

    收获:编码之前必须的思考是逃不掉的,而且这一步是磨刀不误砍柴工,而且会加速以后的步骤 分析: 首要重要的事情是:需要完成的功能,理清逻辑关系.我们要随机产生一定要求的算式,并且计算出算式的值. 其次的 ...

  6. springboot源码之(内嵌tomcat)

    server---service----engine----host-----context---wrapper---servletStandardServer---StandardService-- ...

  7. ueditor的用法

    今天做了一下百度富文本编辑器,遇到了一些问题,现在来总结一下: (1)jQuery没有引用,解决方法:引用jQuery并且放在所有的js前面 (2)没有报错,但是样式显示不出来.解决方法:css引用的 ...

  8. python并发_进程_multiprocessing

    多进程基础, 主要是用了 multiprocessing模块 : 在一个python进程中开启子进程,start方法和并发效果. import time from multiprocessing im ...

  9. Swing学习1——总体概述

    以下来自于JDK1.6 一.Swing学习我划分为两个方面: 一方面Swing的界面设计部分,包括相关组件类的继承关系,组件的功能用途,布局管理: 1.首先继承关系上自上而下为 java.lang.O ...

  10. SQL Server实现读写分离提高系统并发

    转自:http://www.canway.net/Lists/CanwayOriginalArticels/DispForm.aspx?ID=666 在一些大型的网站或者应用中,单台的SQL Serv ...