CATM - The Cats and the Mouse

In a rectangular field of size n by m squares there is a mouse and two cats. The mouse is the first to make a move, then each of the cats makes a move, then again its the mouse's turn, and so on. In each move both the mouse and the cats can move exactly one square vertically or horizontally. If the mouse is standing at the edge of the field then in its next move it can jump off the field and is saved from the cats. If in the next move one of the cats moves to the field with the mouse then there is no escape for the mouse ... =(

You are to write a program which, knowing the initial positions of mouse and the two cats, will find out if there is any way for the mouse to escape from the cats, assuming of course that each cat will do its best to catch the mouse.


In the first line of input two integers n and m are given, not exceeding 100, where n is the number of rows, and m - the number of columns. The second line contains a number k [k <= 10], which defines the number of test cases for the given field. In the next k lines the initial positions of the mouse and the cats are given. The position in the field is given by two numbers: the first is the number of the row, the second is the number of the column. The first two integers are the coordinates of the mouse, the next four integers are the coordinates of the cats.


You must output k lines with answers for each test case. The answer is YES, if the mouse can escape or NO otherwise.


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


Author: Filimonenkov D.O.

hide comments
gourav: 2012-12-16 12:25:52

2 month back , hv read this questn, didnt even got d qstn..but truly very elegant solution.. qustn maker hats off. :-)

Titas Skrebė: 2012-11-19 16:39:09

there is a very elegant solution. do not think too hardly.

Curiosa: 2012-10-16 18:36:30


Last edit: 2012-10-17 08:40:17
Soumajyoti: 2012-07-12 07:18:24

confusing but an interesting one.

shubhang singh chauhan: 2012-06-13 07:19:38

can anyone explain second test case,mouse and both cats are already on the edges so if mouse try to escape then cats will jump off the field in the next move and as the problem says "If in the next move one of the cats moves to the field with the mouse then there is no escape for the mouse ... =(" . So, answer should be NO.

Last edit: 2012-06-13 07:20:28
Anoop Chaurasiya: 2010-05-08 07:58:36

nice one!!! idea is simple but implementation is a bit tricky(be carefull!!!!)

Added by:Roman Sol
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:ZCon 2007