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

来源:互联网 发布:北大青鸟 java周末班 编辑:程序博客网 时间:2024/05/04 02:51


Problem G : One for You


From: DHUOJ, 2017060307
 (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 23 4

 

Sample Output

YESNO

题目意思:

给出一个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
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 政府测量土地少算了面积怎么办 北京武警欠我钱怎么办 被小混混打了怎么办 农保地建房子怎么办 WOW7.3到8.0橙装怎么办 90后离婚有孩子怎么办 90后的我们该怎么办 越南和中国结婚怎么办结婚证 改革怎么看走留怎么办事业怎么干 改革怎么看走留怎么办工作怎么干 军改怎么看我该怎么办 改革怎么办我该怎么干 改革怎么看 走留怎么办 腿又粗又弯怎么办 假发发量太多了怎么办 剃了发际线后悔怎么办 在外面遇到坏人抢劫怎么办 请事假单位不批怎么办 捷普请假不批怎么办 钉钉请假不审批怎么办 钉钉请假未审批怎么办 员工事假+工作履责怎么办 员工请事假不批怎么办 哺乳起员工一直请事假怎么办 请公休公司不批怎么办 辞职信交了不批怎么办 辞职年假没有休完怎么办 病假算旷工我该怎么办 辞职信领导不批怎么办 软顶帽子踏顶了怎么办 戴草帽总往下掉怎么办 白鞋子低帮发黄怎么办 跳伞的时候降落伞打不开怎么办 收腹裤穿着总是往下卷怎么办? 结婚打了黑伞怎么办 酷派x7开不了机怎么办 脸书账号被禁用怎么办 文档变成了d盘怎么办? 派派背包满了怎么办 黑裤子掉颜色了怎么办 快递被别人领走怎么办