F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Ancient vending machine

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 907    Accepted Submission(s): 306


Problem Description
Though the story of Shaolong Xiang, the great time-traveler, is not recorded in the history, some recent discoveries show the possibility that the ancient mystery visitor might really exist. Several months ago, a strange machine was found together with some newly unearthed terra-cotta warriors. That machine looks like a modern machine and even has some electronic parts ¡ª that¡¯s why people take Mr. Xiang into consideration when guessing the origin of the strange machine.

After careful examinations, scientists finally figured out what the machine is -- it actually is a vending machine in Qin dynasty! There is a hole on a panel of the machine, and scientists are pretty sure that Qin people put their coins into the machine through that hole to buy things. As you know, there were too many different types of coins before Qin dynasty and Emperor Qin Shihuang didn¡¯t like that. But scientists found an announcement made by Qin Shihuang carved on the machine, saying that any coins which can go through the hole is still legal to use. Now your task is to determine whether a certain type of coin can be put into the hole¡ªfrom these results we might find some clues about the mystery time-traveler.

The hole on the panel is a polygon and all coins also have a shape of polygon. THEY ALL MAYBE CONCAVE. Scientist found out that ancient people use the vending machine this way: The panel with the hole was positioned horizontally, and the customer chose a best position above the hole to hold a coin. Then the customer dropped the coin. During the process of felling down, the coin WOULD NOT ROTATE in any direction. If the coin could go through the hole, the coin is considered ¡°legal¡±. Otherwise, the coin is judged ¡°illegal¡±. If the coin just merely touched the edges of the hole but was not blocked, it was considered as legal. For example, as shown in the sample input, a square coin with side length 5 can go through a triangle hole with sides of length 3, 4 and 5 , so it¡¯s legal.

Please note that coins and the panel are all considered as no thickness.
 

Input
The first line contains an integer T representing the number of test cases( 0 < T <= 20).
For each test case, the first line contains an integer N (3<=N<=20), representing the number of vertexes of the hole-polygon.
Next N lines describe the shape of the hole-polygon by listing positions of all vertexes in counterclockwise order. Each line contains two real numbers r1 and r2 ( -100 <= r1,r2 <=100), describing the position of a vertex.

The next line contains an integer M (3<=M<=20), representing the number of vertexes of the coin-polygon.

Next M lines describe the shape of the coin-polygon by listing positions of all vertexes in counterclockwise order. Each line contains two real numbers r1 and r2 ( -100 <= r1,r2 <=100), describing the position of a vertex.

The positions mentioned above are relative coordinates but not absolute values.
 

Output
For each test case, output one line containing either the word ¡°legal¡± or the word ¡°illegal¡±, which represents that the coin can or can¡¯t go through the hole.
 

Sample Input
2 4 0 0 4 0 4 1 0 1 3 0 4 1 4 1 0 3 0 0 4 0 0 3 4 0 0 5 0 5 5 0 5
 

Sample Output
legal legal
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-19 06:09:39, Gzip enabled