Guarding Bananas

时间:2023-03-08 19:42:43

Guarding Bananas

Once there was a lazy monkey in a forest. But he loved banana too much. One day there was a storm in the jungle and all the bananas fell from the trees. The monkey didn't want to lose any of the bananas. So, he wanted to find a banana such that he can eat that and he can also look after the other bananas. As he was lazy, he didn't want to move his eyes too wide. So, you have to help him finding the banana from where he can look after all the bananas but the degree of rotating his eyes is as small as possible. You can assume that the position of the bananas can be modeled as 2D points.

Here a banana is shown, from where the monkey can look after all the bananas with minimum eye rotation.

Input

Input starts with an integer T (≤ 13), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 105) denoting the number of bananas. Each of the next n lines contains two integers x y (-109 ≤ x, y ≤ 109) denoting the co-ordinate of a banana. There can me more than one bananas in the same co-ordinate.

Output

For each case, print the case number and the minimum angle in degrees. Errors less than 10-6 will be ignored.

Sample Input

2

1

4 4

4

0 0

10 0

10 10

2 1

Sample Output

Case 1: 0

Case 2: 45.0000000

Hint

Dataset is huge. Use faster I/O methods.

没有什么好说的,求凸包面积,直接上模板.

 #include<cstdio>
 #include<cstring>
 #include<cmath>
 #include<iostream>
 #include<algorithm>
 using namespace std;
 ;
 const double PI=acos(-1.0);
 ;
 :x<?-:;}
 struct point{double x,y;}a[maxn],ch[maxn];
 bool operator < (point x,point y){return x.x<y.x||x.x==y.x&&x.y<y.y;}
 bool operator == (point x,point y){return x.x==y.x&&x.y==y.y;}
 point operator - (point x,point y){point ret; ret.x=x.x-y.x,ret.y=x.y-y.y; return ret;}
 double angle(point x){return atan2(x.y,x.x);}
 double cross(point x,point y){return x.x*y.y-x.y*y.x;}
 int Andrew(point *a, int n, point *ch){
     sort(a,a+n);
     ;
     ; i<n; i++) {
          &&dcmp(cross(ch[m-]-a[i],ch[m-]-a[i])) <= ) m--;
         ch[m++]=a[i];
     }
     int k=m;
     ; i>=; i--) {
         ]-a[i],ch[m-]-a[i])) <= ) m--;
         ch[m++]=a[i];
     }
     ) m--;
     return m;
 }
 int main(){
     int T,n,ts;
     ; ts<=T; ts++){
         scanf("%d",&n);
         ; i<n; i++) scanf("%lf%lf", &a[i].x,&a[i].y);
         ){printf("Case %d: 0.0000000\n",ts); continue;}
         n=Andrew(a,n,ch);
         ; i<; i++) ch[i+n]=ch[i];
         double mini=1e10;
         ; i<n; i++){
             ]);
             ]-ch[i+]);
             double da=fabs(ang1-ang2);
             if (da>PI) da=2.0*PI-da;
             mini=min(mini,da*180.0/PI);
         }
         printf("Case %d: %.7f\n",ts,mini);
     }
     ;