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

转载于:https://www.cnblogs.com/xiao-xin/articles/4369104.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值