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;
}
- python基础知识——内置数据结构(元组)
- python基础知识——控制语句
- python基础知识——基本语法
- 11g主库归档自动删除的小问题分析 (r8笔记第1天)
- JavaWeb02-CSS,JS(Java真正的全栈开发)
- 数据处理——One-Hot Encoding
- JavaWeb20-文件上传;下载(Java真正的全栈开发)
- 转--每周一个GoLang设计模式之组合模式
- 简单易学的机器学习算法——Softmax Regression
- JavaWeb19-Listener ; Filter
- dataguard归档路径的问题(r7笔记第99天)
- 厚土Go学习笔记 | 34. 一个简单的 web 服务器实现
- JavaWeb18-jquery学习笔记(Java全栈开发)
- 简单易学的机器学习算法——Apriori算法
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- gym 搭建 RL 环境
- MNIST练习
- Dinosaurus_Island_Character_level_language_model_final_v3b
- Trigger_word_detection_v1a
- 《深入浅出SQL》问答录(二)
- 《深入浅出SQL》问答录(四)
- 《深入浅出MySQL》问答录(五)
- 《深入浅出SQL》问答录(七)
- 《深入浅出SQL》问答录(八)
- Improvise_a_Jazz_Solo_with_an_LSTM_Network_v3a-2
- 《深入浅出SQL》问答录(九)
- 《深入浅出SQL》问答录(十)
- Operations_on_word_vectors_v2a
- LeetCode精选好题(一)
- LeetCode精选好题(二)