Magic Towers and Teleportation
Time limit2sMemory limit512 MB
Decide whether repeatedly reflecting the whole set of points across three fixed towers can turn one given point multiset into another, with soldiers considered indistinguishable.
- Level
Hard8 of 10
- Topics
- Geometry, Math, Brute force, Implementation
- Solved
- No attempts yet
Problem
An enemy army struck King Kangho from a direction he never expected, so Kangho has to redeploy his troops in a hurry. He handed the job to the wizard Minho.
Minho owns three magic towers that teleport an army. Activating one tower moves every soldier to a new place at the same time. The new place is the point symmetric to the old place about that tower. The tower therefore sits at the midpoint of the segment joining a soldier's old place and new place.
Kangho can activate the three towers in any order and as many times as he likes, and he can activate the same tower more than once. He can also activate no tower at all.
You are given the current positions of the soldiers, the positions Kangho wants, and the coordinates of the three magic towers. Write a program that decides whether Kangho can turn the current arrangement into the arrangement he wants.
A soldier cannot move except by teleportation. Soldiers are indistinguishable, so their numbering does not have to be preserved. The soldier standing at the first coordinate of the input may end up at the third coordinate of the desired arrangement.
Input
The first line contains the number of soldiers ().
Each of the next lines contains the current coordinates and of one soldier, separated by a space.
Each of the following lines contains one position Kangho wants, in the same format.
The last lines contain the coordinates of the magic towers.
Every coordinate is an integer between and .
Output
Print 1 if Kangho can produce the arrangement he wants, and 0 otherwise.