Problem G : One for You
From: DHUOJ, 2017060307
(Out of Contest)
题目意思:
给出一个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;
}