Codeforces Beta Round #51 C. Pie or die 博弈论找规律 有趣的题~

时间:2024-09-22 08:05:19

C. Pie or die

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/55/problem/C

Description

Volodya and Vlad play the following game. There are k pies at the cells of n  ×  m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy

Input

First line contains 3 integers, separated by space: 1 ≤ n, m ≤ 100 — dimensions of the board and 0 ≤ k ≤ 100 — the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≤ x ≤ n, 1 ≤ y ≤ m — coordinates of the corresponding pie. There could be more than one pie at a cell.

Output

Output only one word: "YES" — if Volodya wins, "NO" — otherwise.

Sample Input

2 2 1
1 2

Sample Output

YES

HINT

题意

给你n*m的格子,有k次询问,每次询问就是给你一个球的位置

球可以向四周边相邻的位置移动,如果这个棋子走到边界上,并且这个边界还没有被ban的话,Volodya就胜利了

Volodya先走,然后再ban一个边界

问你K次询问中,Volodya是否能够至少胜利一场

题解:

结论很简单,但是这个怎么来的呢?首先你得ban掉离他最近的边界的边,以及这个边的左边和右边,以及上面和下面

比如下图,红色是棋子所在地,你必须在他到达边界前ban掉五条边

Codeforces Beta Round #51 C. Pie or die 博弈论找规律 有趣的题~

代码:

#include<iostream>
#include<stdio.h>
using namespace std; int main()
{
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
int flag = ;
for(int i=;i<k;i++)
{
int x,y;
scanf("%d%d",&x,&y);
if(x<=||(n-x)<=)
flag = ;
if(y<=||(m-y)<=)
flag = ;
}
if(flag==)
return puts("YES");
else
return puts("NO");
}