Codeforces 1848A Vika and Her Friends

文章描述了一个在购物中心的网格中,Vika试图从她的朋友们中逃脱的问题。每个参与者每分钟可以移动到相邻的房间。关键在于计算Vika与每个朋友的曼哈顿距离,如果存在偶数距离的情况,Vika将无法永远逃脱。给定每个朋友的初始位置,需要判断是否存在这样的情况。题目提供了一些输入输出示例来解释问题和解决方案。解答此问题需要理解曼哈顿距离并应用简单的数学逻辑。
摘要由CSDN通过智能技术生成

题目描述:

Vika and her friends went shopping in a mall, which can be represented as a rectangular grid of rooms with sides of length nn and mm. Each room has coordinates (a,b)(a,b), where 1≤a≤n,1≤b≤m1≤a≤n,1≤b≤m. Thus we call a hall with coordinates (c,d)(c,d) a neighbouring for it if |a−c|+|b−d|=1|a−c|+|b−d|=1.

Tired of empty fashion talks, Vika decided to sneak away unnoticed. But since she hasn't had a chance to visit one of the shops yet, she doesn't want to leave the mall. After a while, her friends noticed Vika's disappearance and started looking for her.

Currently, Vika is in a room with coordinates (x,y)(x,y), and her kk friends are in rooms with coordinates (x1,y1)(x1,y1), (x2,y2)(x2,y2), ... ,(xk,yk),(xk,yk), respectively. The coordinates can coincide. Note that all the girls must move to the neighbouring rooms.

Every minute, first Vika moves to one of the adjacent to the side rooms of her choice, and then each friend (seeing Vika's choice) also chooses one of the adjacent rooms to move to.

If at the end of the minute (that is, after all the girls have moved on to the neighbouring rooms) at least one friend is in the same room as Vika, she is caught and all the other friends are called.

Tell us, can Vika run away from her annoying friends forever, or will she have to continue listening to empty fashion talks after some time?

Input

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤1001≤t≤100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains three integers nn, mm, kk (1≤n,m,k≤1001≤n,m,k≤100) — the sizes of the mall and the number of Vika's friends.

The second line of each test case contains a pair of integers xx and yy (1≤x≤n1≤x≤n, 1≤y≤m1≤y≤m) — the coordinates of the room where Vika is.

Each of the next kk lines of each test case contains a pair of integers xixi and yiyi (1≤xi≤n1≤xi≤n, 1≤yi≤m1≤yi≤m) — the coordinates of the room where the ii-th friend is.

Output

For each test case, output "YES" if Vika can run away from her friends forever, otherwise output "NO".

You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.

input

6
2 2 1
1 1
1 2
2 2 2
1 1
2 2
2 2
1 2 1
1 1
1 2
5 5 4
3 3
1 1
1 5
5 1
5 5
2 2 2
1 1
2 1
1 2
3 4 1
1 2
3 3

output

YES
NO
YES
NO
YES
YES

题目大意:给你一个点(x,y)以及其余k个点,每一个点在每一分钟都会向相邻的位置走一步。问在某分钟,k个点中是否至少有一个点和(x,y)点在一个位置。

思路分析:对于k个点中的任意一个点和(x,y)点,在某一个分钟,它们之间的曼哈顿距离要么不变,要么增加2,要么减少2,所以只要这k个点中有一个点和(x,y)点的曼哈顿距离为偶数,就在某一分钟会相遇,否则不会。

代码:

#include<iostream>
#include<cstring>
using namespace std;
int a[105],b[105];
int main(){
	int t;
	cin>>t;
	while(t--){
		int n,m,k,flag=0;
		cin>>n>>m>>k;
		int x,y;
		cin>>x>>y;
		int f=(x+y)%2;
		for(int i=0;i<k;i++){
			cin>>a[i]>>b[i];
		}
		for(int i=0;i<k;i++){
			if((a[i]+b[i])%2==f){
				flag=1;
				cout<<"NO\n";
				break;
			}
		}
		if(flag==0)
		cout<<"YES\n";
	}
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值