COD1 - Save the cows!
There is a green square grid of size nXm with k cows in it.
The objective of the cows is to escape the field.If any one of the cows escape all cows are set free.
There is a farmer who tries to restrict the field by putting up fences along the border .Initially the grid is not fenced.
Cows coordinate and think of a plan to escape.Cows get the first move.Cows and farmer move alternatively.At any move any one of the k cows can move to their neighboring cell(the cell that shares an edge with it).If the cow is already at the edge of the field and the edge is not fenced then it can escape it and hence all cows are set free.After every move of the cows the farmer can fence some edge at the border of the field of length 1 so that no cow is able to escape from that edge anymore.
The question is:"Will the innocent cows manage to escape?"
First line contains T-number of test cases(0<T<=100)
Each test case contains 3 integers, separated by space: 1≤n,m≤100 — dimensions of the field and 0≤k≤100 — the number of cows. Each of the next k lines contains 2 integers, separated by space: 1≤x≤n, 1≤y≤m — coordinates of the corresponding cow. There could be more than one cow at a cell.
Output one word: "YES" — if cows escape, "NO" — otherwise.
12 2 1 1 2 Output: YES
Easy one. Just think of all possibilities when the cow can't escape from the field.Last edit: 2021-04-01 14:40:07
good one easy but tricky........
This seems to give WA with print writer in JAVA. You have been warned .
Last edit: 2014-12-23 20:25:21
If there are no cows (K=0), they do not escape.