Codeforces Beta Round #51 C. Pie or die(博弈 思維)

C. Pie or die

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples

input

Copy

2 2 1
1 2

output

Copy

YES

input

Copy

3 4 0

output

Copy

NO

input

Copy

100 50 2
50 25
50 25

output

Copy

NO

題意:兩個人博弈,在一張棋盤上,可以移動棋子,一方只要將棋子移出就算勝利,另一方要做的是圍堵,每次可以封鎖一單位長度,在兩個人都足夠聰明的情況下判斷誰能獲勝

思路:這題無關編程算法哈哈,純屬一道思維題,我們可以這樣考慮,其實按理來說你在內部走無所謂,但要贏就得有到邊界的一步,但是一開始我是想在邊界的話你追我堵一定是放棋子的贏,因爲邊界(左上角,右上角,左下角,右下角)有兩個缺口,所以肯定堵不過來,但是如果是在內部一點點的話我就可以騰出步數來修補這些空缺,具體而言只要領先四步即可,所以要求x至少爲6或者n-5,n爲行數(具體爲什麼可以推導一下,比如6,距離1有五個空格,四個留着填缺口,最後一步是放棋子先走,所以要五個空),那這道題目就做出來啦

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rg register ll
#define inf 2147483647
#define lb(x) (x&(-x))
template <typename T> inline void read(T& x)
{
    x=0;char ch=getchar();ll f=1;
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}x*=f;
}
ll n,m,k;
int main()
{
	cin>>n>>m>>k;
	ll flag=1;
	if(!k)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	for(int i=0;i<k;i++)
	{
		ll x,y;
		cin>>x>>y;
		if((x>=6&&x<=n-5)&&(y>=6&&y<=m-5))
		{
			flag=1;
		}
		else 
		{
			flag=0;
			break;
		}
	}
	flag?cout<<"NO"<<endl:cout<<"YES"<<endl;
    return 0;
    
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章