CodeForces 257C View Angle :二维平面上一些点,从原点射出两条射线将它们全部包括,求最小夹角 :几何+技巧

将每个点与x正半轴夹角利用atan求出来,都在[0,360)之间

然后排序,枚举夹角相邻的两个点,ans=min(360-(the[i+1]-the[i])) 1<=1<n

注意最后判断下第一条和最后一条之间夹角

 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<string.h>
 4 #include<algorithm>
 5 #define eps 1e-10
 6 using namespace std;
 7 double the[100005];
 8 int main()
 9 {
10   int n,i;
11   double x,y,minx;
12   scanf("%d",&n);
13   for (i=1;i<=n;i++)
14   {
15     scanf("%lf%lf",&x,&y);
16     if (x==0) {
17       if (y>0) the[i]=90;
18       else the[i]=270;
19     }
20     else{
21       the[i]=atan(y/x)*180/3.141592653579793;
22       if (fabs(the[i])<=eps){
23         if (x<0) the[i]=180;
24       }
25       else if (the[i]<=eps) {
26         if (x>0) the[i]+=360;
27         else the[i]+=180;
28       }
29       else if (x<0) the[i]+=180;
30     }
31   }
32   sort(the+1,the+n+1);
33   minx=the[n]-the[1];
34   for (i=1;i<n;i++)
35     if (360-(the[i+1]-the[i])<minx) minx=360-(the[i+1]-the[i]);
36   printf("%.12lf\n",minx);
37   return 0;
38 }
View Code

题目链接:http://codeforces.com/problemset/problem/257/C

posted on 2015-03-26 16:11  xiao_xin  阅读(306)  评论(0编辑  收藏  举报

导航