Guarding Bananas

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.

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

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cmath>
 4 #include<iostream>
 5 #include<algorithm>
 6 using namespace std;
 7 const double eps=1e-8;
 8 const double PI=acos(-1.0);
 9 const int maxn=100005;
10 int dcmp(double x){return fabs(x)<eps?0:x<0?-1:1;}
11 struct point{double x,y;}a[maxn],ch[maxn];
12 bool operator < (point x,point y){return x.x<y.x||x.x==y.x&&x.y<y.y;}
13 bool operator == (point x,point y){return x.x==y.x&&x.y==y.y;}
14 point operator - (point x,point y){point ret; ret.x=x.x-y.x,ret.y=x.y-y.y; return ret;}
15 double angle(point x){return atan2(x.y,x.x);}
16 double cross(point x,point y){return x.x*y.y-x.y*y.x;}
17 int Andrew(point *a, int n, point *ch){
18     sort(a,a+n);
19     int m=0;
20     for (int i=0; i<n; i++) {
21         while (m > 1 &&dcmp(cross(ch[m-2]-a[i],ch[m-1]-a[i])) <= 0) m--;
22         ch[m++]=a[i];
23     }
24     int k=m;
25     for (int i=n-2; i>=0; i--) {
26         while (m>k&&dcmp(cross(ch[m-2]-a[i],ch[m-1]-a[i])) <= 0) m--;
27         ch[m++]=a[i];
28     }
29     if (n>1) m--;
30     return m;
31 }
32 int main(){
33     int T,n,ts;
34     for (scanf("%d",&T),ts=1; ts<=T; ts++){
35         scanf("%d",&n);
36         for (int i=0; i<n; i++) scanf("%lf%lf", &a[i].x,&a[i].y);
37         if (n<3){printf("Case %d: 0.0000000\n",ts); continue;}
38         n=Andrew(a,n,ch);
39         for (int i=0; i<10; i++) ch[i+n]=ch[i];
40         double mini=1e10;
41         for (int i=0; i<n; i++){
42             double ang1=angle(ch[i]-ch[i+1]);
43             double ang2=angle(ch[i+2]-ch[i+1]);
44             double da=fabs(ang1-ang2);
45             if (da>PI) da=2.0*PI-da;
46             mini=min(mini,da*180.0/PI);
47         }
48         printf("Case %d: %.7f\n",ts,mini);
49     }
50     return 0;
View Code

 

转载于:https://www.cnblogs.com/whc200305/p/7183959.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值