Cow uncle has learned how to use the cross product. The cross product is really good.

Source: Internet
Author: User
Cow uncle Time limit:4000/2000 ms (Java/Others) Memory limit:128000/64000 KB (Java/others) submitstatusproblem description

South China algorithm University (scau) is a campus with excellent ecological environment. On the School Road, you can see cattle, sheep, dogs, chickens, ducks, geese, and so on.

It is of course not nobody can take care of Niu's school path. Uncle Niu will usually take the nheaded calf to a wide lawn to graze, M pieces of big stone on the grass, Uncle Niu will sit on the stone, watching this group of calves. Of course, not all stone positions are so good. Uncle Fang Niu wants to watch all the cows, so the field of view of the selected position P must be less than 180 degrees (that is, in front of him, the angle between the leftmost ox A and rightmost ox B and P cannot be greater than or equal to 180 degrees ).

Now we have the position of the nheaded calf and then the M stone. Please find out whether each stone can look at all the cows. If possible, obtain the field of view degree at the corresponding position. (It can be assumed that the calf will not graze on the stone, and the calf will not eat grass in the same position)

Input

Multiple groups of data are input.

The first number of cattle in each group is N, And the next n rows have two numbers (XI, Yi) in each row, indicating the place of cattle.

Next is the number of stones m, and then the m row has two numbers (XJ, YJ) in each row, indicating the position of the stones.

Data range:

3 ≤ m, n ≤ 1000

| Xi |, | Yi | ≤ 1000000

Input data ensures that not all cows are in the same straight line.

 

Output

Output a line for each stone. If you can see all the cows in the field of view at this position, the degree of the field of view at this position is displayed (two decimal places are retained ). Otherwise, "Bad Position" is output ".

 

Sample Input
40 01 01 10 130.5 0.51 0.52 0
Sample output
Bad PositionBad Position45.00


1 # include <iostream> 2 # include <algorithm> 3 # include <math. h> 4 # include <stdio. h> 5 using namespace STD; 6 # define PI 3.1415926535898 7 struct point 8 {9 Double X, Y; 10}; 11 point P [1005], Res [1005]; 12 int n, top; 13 double dist (const point & arg1, const point & arg2) 14 {15 return SQRT (1.0 * (arg1.x-arg2.x) * (arg1.x-arg2.x) + (arg1.y-arg2.y) * (arg1.y-arg2.y); 16} 17 bool multi (point P0, Point P1, Po Int P2) 18 {19 Return (p1.x-converted X) * (p2.y-converted y)> = (p2.x-converted X) * (p1.y-converted y ); 20} 21 bool CMP (const point & A, const point & B) 22 {23 point temp = P [0]; 24 Double XMT = (. x-temp.x) * (B. y-temp.y)-(B. x-temp.x) * (. y-temp.y); 25 if (XMT) // The vector is not Collocated and the 26 return XMT> 0; 27 return dist (A, temp)> dist (B, temp ); // obtain the longest number of vectors. 28} 29 void Graham () // P [0] is the element 30 in the lower left corner {31 res [0] = P [0]; 32 sort (p + 1, P + N, CMP); // sort 33 res [1] = P [1]; 34 res [2] = P [2]; 35 Top = 2; 36 For (INT I = 3; I <n; I ++) 37 {38 While (multi (P [I], Res [Top], res [Top-1]) 39 top --; 40 res [++ top] = P [I]; 41} 42} 43 bool check (point temp) 44 {45 int I, m = multi (temp, Res [0], Res [1]); 46 for (I = 1; I <top; I ++) 47 {48 if (multi (temp, Res [I], Res [I + 1])! = M) return 0; 49} 50 if (multi (temp, Res [I], Res [0])! = M) return 0; 51 return 1; 52} 53 void work (point temp) 54 {55 int Bi, en; 56 Bi = en = 0; 57 for (INT I = 1; I <= top; I ++) 58 {59 If (multi (temp, Res [I], Res [bi]) bi = I; 60 if (multi (temp, Res [En], Res [I]) en = I; 61} 62 double ans = atan2 (RES [En]. y-temp.y, Res [En]. x-temp.x)-atan2 (RES [bi]. y-temp.y, Res [bi]. x-temp.x); 63 If (ANS <0.0) ans + = 2 * PI; 64 ans = ans * 180/PI; 65 printf ("%. 2lf \ n ", ANS); 66} 67 int main () 68 {69 int I, Mina, M; 70 point te MP; 71 while (~ Scanf ("% d", & N) 72 {73 scanf ("% lf", & P [0]. x, & P [0]. y); 74 Mina = 0; 75 for (I = 1; I <n; I ++) 76 {77 scanf ("% lf ", & P [I]. x, & P [I]. y); 78 If (P [I]. Y <p [Mina]. Y | (P [I]. y = P [Mina]. Y & P [I]. x <p [Mina]. x) 79 Mina = I; 80} 81 swap (P [0]. x, p [Mina]. x), swap (P [0]. y, P [Mina]. y); 82 Graham (); 83 scanf ("% d", & M); 84 while (M --) 85 {86 scanf ("% lf ", & temp. x, & temp. y); 87 If (check (temp) 88 {89 printf ("bad position \ n"); 90} 91 else92 {93 work (temp ); 94} 95} 96} 97}
View code

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.