zoukankan      html  css  js  c++  java
  • II play with GG(思维规律)

    时间限制:C/C++ 1秒,其他语言2秒
    空间限制:C/C++ 262144K,其他语言524288K
    64bit IO Format: %lld

    题目描述

    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 1

    输出

    复制

    ii

    示例2

    输入

    复制

    124 654

    输出

    复制

    gg

    思路:这个题的常规解法应该是SG函数,但是自己在纸上推一下能发现如代码所示的规律

    代码:

    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    #include<cstring>
    
    using namespace std;
    
    int main()
    {
    	int a,b;
    	cin>>a>>b;
    	if(a%2==0&&b%2==0)
    	{
    		cout<<"gg"<<endl;
    	}
    	else
    	{
    		cout<<"ii"<<endl;
    	}
    	
    	return 0;
    } 
  • 相关阅读:
    Spring MVC的Controller统一异常处理:HandlerExceptionResolver
    spring mvc 404页面制作
    MyEclipse导出可运行的jar包
    Spring的编程式事务和声明式事务
    数据库SQL优化大总结
    LinkedList源码及原理
    ArrayList源码分析
    HashMap源码及原理
    Java集合框架常见面试题
    idea获取激活码
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10781856.html
Copyright © 2011-2022 走看看