#Lutece0105. Apple Pie
Apple Pie
Migrated from Lutece 105 Apple Pie
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Apple pie is Hysramp's favorite snack for tasting so cloying, which usually formed in circular appearance. Although exotic and delicious, apple pie is not so abstruse of its cooking method. Just as the figure shows, looks pretty charming ,apple pie is often make of a big round bread and several pieces of apple slices.
However, what often discomfit Hysramp is, everyone may meet, mouth appears not big enough to touch any apple slices when eat the apple pie for the first bite. Now given the apple pie and the bite mark, you’re required to tell how many apple slices have Hysramp touched.
To simplify the problem, we do some reasonable assumptions. Apple pie (yellow part) and apple slices (red parts) on it all are exact circles. Each circle will be described by an for radius and , for centre. The bite mark on the apple pie must be a minor arc (the blue arc), which will be given by two points and a radius . These two points will be guaranteed on the edge of apple pie, thus they (the two points) will be indicated by two degree , , which is the degrees from the positive -axis on coordinate system which the origin is on the apple pie's centre, just as illustrated below.
Input
The first line of the input contains one integer , which indicate the number of test cases. Following each test case will be separated by a blank line.
For each test, the first line would be four integers, , , , , separate by spaces, which are radius and centre coordinate of the apple pie (yellow), then followed by lines. Each line has three integers , , , separate by spaces, describing the apple slices (red). The last line of each test case is , and , in degree (), which mentioned in the problem. And all data will be less than .
Output
One line for each test case, output Bad Apple Pie
if any apple slices fails to lie completely in the apple pie, or write the number of apple slices Hysramp can touch with the given bite mark.
Samples
1
100 200 170 2
30 140 180
50 220 180
100 160 70
2
Note
- Apple slices (the red parts) may not completely lie in the apple pie (the yellow part), if so, output
Bad Apple Pie
. - The apple slices (the red parts) may overlap on each other, but it doesn't matter.
- The bite mark will always be a minor arc and Hysramp would never bite off the centre of the apple pie for some reasons.
- Ex-tangency of a circle and arc also means
touch
, and in-tangency of two circles also meansinclude
.
Resources
The 7th UESTC Programming Contest Final