Superknight
Time limit3sMemory limit128 MB
For each knight, decide whether the move vectors generate the full integer lattice of board squares.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Geometry
- Solved
- No attempts yet
Problem
On an infinite chequered board there is a superknight that can make several kinds of moves. Each kind of move is described by two integers. The first tells how many columns the knight traverses (to the right if the number is positive, to the left if it is negative), and the second tells how many rows it traverses (forward if the number is positive, backward if it is negative).
Write a program that:
- reads from standard input the data describing several superknights,
- determines for each superknight whether it can reach any square of the board using only the allowed moves,
- writes the results to standard output.
Input
The first line of input contains one integer , the number of data sets (). It is followed by data sets. The first line of each set contains an integer , the number of kinds of moves the superknight can make (). Each of the next lines contains two integers and separated by a single space (), describing one kind of move.
Output
The output should consist of lines. The -th line should contain the word TAK ("yes") if the superknight described by the -th data set can reach any square of the board, or the word NIE ("no") otherwise.