随笔 - 346,  文章 - 0,  评论 - 39,  阅读 - 26万

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 (m, n), 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 m, n (2 ≤ m, n ≤ 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;
}
posted on   渡……  阅读(393)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示