2017年上海金马五校程序设计竞赛:Problem G : One for You


Problem G : One for You


 (Out of Contest)

Time Limit: 1 s

Description

Given a m × n chessboard, a stone is put on the top-left corner (1, 1). Kevin and Bob take turns moving the stone. One can only move the stone one block right or downward and cannot stay in the same block. Kevin goes first and the one who cannot move will lose the game.

However, Bob thinks the game is somehow unfair. So she proposes to get one chance to hack one block to make it inaccessible before the game starts. Notice that she can only hack no more than one block. She can choose any block except top-left corner (1, 1) and bottom-right corner (mn), and then hack it. After the game starts, both players cannot move stone onto the hacked block.

Help Bob to find out the strategy to choose the block in case of win if there is a way.

 

Input

There are several test cases.
Each test case contains a line with two integers mn (2 ≤ mn ≤ 2,000,000,000).

 

Output

For each test case, if there is no solution, print "NO", else print "YES" in one line.

 

Sample Input

2 2
3 4

 

Sample Output

YES
NO

题目意思:

给出一个m*n的二维数组,这个二维数组中有一个石子,在(1,1)位置,现在两个人要玩一个推石子的游戏,推的时候每次只能推一格而且

只能向右推和向下推,两个人轮换着推石子(每次必须推,石子的位置必须移动),当轮到某个人推的时候,发现石子不能移动了,这个人

就输了。游戏规定Kevin先推,Bob后推但是Bob觉得这对它不公平,因此现在允许Bob最多可以堵一个方格(不能堵(1,1)位置,也不能

堵(m,n)位置),他可以在游戏开始前选择堵一个方格(当然也可以放弃这个堵方格的机会,在原地图上玩),游戏开始后Bob就没权利改

变石子的位置了。问给出一个m*n的数组,问Bob能不能赢。

解题思路:

博弈问题,关键考虑怎么去博。首先推石子只能向下或向右推:则可以很容易得出下面图中结论。


接下来来看,如果推动石子的总次数是奇数的时候,下图分析怎样去堵格子Bob能赢,从而得出结论:



#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;

int main()
{
    long long m,n;  ///m行n列
    while(~scanf("%lld%lld",&m,&n))
    {
        long long step = (m-1)+(n-1);
        if(step%2==0)  ///偶数步,不用堵就可以赢
            printf("YES\n");
        else
        {
            int a,b;
            if(m<n)  
            {
                a = m; b = n;
            }
            else
            {
                a = n; b = m;
            } 
            ///上面都啰嗦,其实看abs(m-n)就OK
            if(b-a == 1)
                printf("NO\n");
            else
                printf("YES\n");
        }
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值