链接: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. db2常用语句

    连接数据库 db2 connect to chmgmdb user ch_mgm 断开数据库 db2 disconnect current 查询 db2 "select * from btp ...

  2. 小白的python之路Linux部分10/27&28

     用户 创建流程模拟 总代码 [root@localhost ~]# vim /etc/passwd #1 [root@localhost ~]# mkdir /home/rose [root@loc ...

  3. 网络编程-day2

    1 网络通信协议 Tcp udp的区别 重点(*****) TCP(Transmission Control Protocol)可靠的.面向连接的协议(eg:打电话).传输效率低全双工通信(发送缓存& ...

  4. Unity实现用户条款弹窗及登录

    首先来看效果图... 1.先编辑页面 1)新建登录按钮,更名为Login 2)新建toggle,新建方式如下图 调整toggle的大小和位置到适当的范围. 3)新建同意用户条款按钮,步骤为新建UI-& ...

  5. 阿里云oss c# api 的使用 的使用

    API 文档下载地址:http://docs-aliyun.cn-hangzhou.oss.aliyun-inc.com/assets/attach/32085/cn_zh/1515493045734 ...

  6. apk的api级别不要低于26

    谷歌要求 api级别 最低26, 在用 xbuliber打包app的时候,可以在 manifest.json增加下面的代码. "plus": { "distribute& ...

  7. JAVAEE 第八周

    equals():反映的是对象或变量具体的值,即两个对象里面包含的值--可能是对象的引用,也可能是值类型的值. hashCode():计算出对象实例的哈希码,并返回哈希码,又称为散列函数.根类Obje ...

  8. 汉明码(Hamming)编码与纠错原理

    一 汉明码的编解码说明 (一)编码 Hamming(12,8) N=12,表示编码后的比特长度 K=8,待编码数据的比特长度 R=N-K=4,校验位的比特长度 D=3 汉明距离:相邻行之间不同比特数据 ...

  9. CSS&JS小结

    回顾:html: 作用:展示 文件标签: <html> <head> <title></title> </head> <body> ...

  10. PHP协程入门详解

    概念 咱们知道多进程和多线程是实现并发的有效方式.但多进程的上下文切换资源开销太大:多线程开销相比要小很多,也是现在主流的做法,但其的控制权在内核,从而使用户(程序员)失去了对代码的控制,而且线程的上 ...