hdu 3532 Max Angle(atan2的使用)

Max Angle

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 678    Accepted Submission(s): 238


Problem Description
Given many points in a plane, two players are playing an interesting game.

Player1 selects one point A as the vertex of an angle. Then player2 selects other two points B and C. A, B and C are different with each other. Now they get an angle B-A-C.

Player1 wants to make the angle as large as possible, while player2 wants to make the angle as small as possible.

Now you are supposed to find the max angle player1 can get, assuming play2 is c lever enough.
 

 

Input
There are many test cases. In each test case, the first line is an integer n (3 <= n <= 1001), which is the number of points on the plane. Then there are n lines. Each contains two floating number x, y, witch is the coordinate of one point. n <= 0 denotes the end of input.
 

 

Output
For each test case, output just one line, containing the max angle player1 can get in degree format. The result should be accurated up to 4 demicals.
 

 

Sample Input
3 0 0 2 0 0 5 -1
 

 

Sample Output
90.0000
 

 

Source
 

 

题意是说。先选一个点A,然后选两个点B,C。 使得每个A对应的最小角B-A-C最大。
 
我们可以枚举每个点,然后求得这个点和其他所有点所成的角度,排序后找到一组相邻的差值最小的,记录为mn
然后对于每个点得到的mn,记录最大的一个,就是答案。
 
角度怎么搞呢...
atan2(y,x)是个好东西。
atan2(y,x)表示点(0,0)到(x,y)的射线与x轴正向所成的角度,取值范围介于 -pi 到 pi 之间(不包括 -pi),
 
我们可以处理下把角度变成0到2*pi之间。
 

还要注意直线的角度不可能是钝角。所以如果答案为钝角记得取补。
 
1A,开心。
 
  1 /*************************************************************************
  2     > File Name: code/hdu/3552.cpp
  3     > Author: 111qqz
  4     > Email: rkz2013@126.com 
  5     > Created Time: 2015年11月09日 星期一 10时20分55秒
  6  ************************************************************************/
  7 
  8 #include<iostream>
  9 #include<iomanip>
 10 #include<cstdio>
 11 #include<algorithm>
 12 #include<cmath>
 13 #include<cstring>
 14 #include<string>
 15 #include<map>
 16 #include<set>
 17 #include<queue>
 18 #include<vector>
 19 #include<stack>
 20 #include<cctype>
 21 #define fst first              
 22 #define sec second      
 23 #define lson l,m,rt<<1
 24 #define rson m+1,r,rt<<1|1
 25 #define ms(a,x) memset(a,x,sizeof(a))
 26 using namespace std;
 27 const double eps = 1E-8;
 28 const int dx4[4]={1,0,0,-1};
 29 const int dy4[4]={0,-1,1,0};
 30 typedef long long LL;
 31 const int inf = 0x3f3f3f3f;
 32 const double pi = acos(-1.0);
 33 const int N=1E3+7;
 34 int n;
 35 double ang[N];
 36 int dblcmp( double d)
 37 {
 38     return d<-eps?-1:d>eps;
 39 }
 40 struct point
 41 {
 42     double x,y;
 43     point(){}
 44     point (double _x,double _y):
 45     x(_x),y(_y){};
 46 
 47     void input()
 48     {
 49     scanf("%lf %lf",&x,&y);
 50     }
 51 
 52     double myatan2(point p)
 53     {
 54     double res = atan2(p.y-y,p.x-x);
 55     return res>0?res:res+2*pi;
 56     }
 57 }p[N];
 58 
 59 int main()
 60 {
 61   #ifndef  ONLINE_JUDGE 
 62    freopen("in.txt","r",stdin);
 63   #endif
 64    
 65     while (scanf("%d",&n)!=EOF)
 66     {
 67     if (n<=0) break;
 68     for ( int i = 0 ; i < n ; i++) p[i].input();
 69     
 70         double mx = 0;
 71     for ( int i = 0 ; i < n ; i++ )
 72     {
 73         int cnt = 0 ;
 74         for ( int j = 0 ; j < n ;j++)
 75         {
 76         if (i==j) continue;
 77         ang[cnt++] = p[i].myatan2(p[j]);
 78         }
 79         sort(ang,ang+cnt);
 80         double mn = 999999;
 81         for ( int j = 0 ; j < cnt-1 ; j++)
 82         {
 83         double tmp = ang[j+1]-ang[j];
 84         if (dblcmp(tmp-pi)>0)   //直线的夹角不可能是钝角
 85         {
 86             tmp = 2*pi-tmp;
 87         }
 88         mn = min(tmp,mn);
 89         }
 90         mx = max(mn,mx);
 91     }
 92     printf("%.4f\n",mx*(180.0/pi));
 93 
 94     }
 95   
 96    
 97  #ifndef ONLINE_JUDGE  
 98   #endif
 99   fclose(stdin);
100     return 0;
101 }
View Code

 

 

转载于:https://www.cnblogs.com/111qqz/p/4949392.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值