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
2010 ACM-ICPC Multi-University Training Contest(10)—-Host by HEU
题意是说。先选一个点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))
26using namespace std;
27const double eps = 1E-8;
28const int dx4[4]={1,0,0,-1};
29const int dy4[4]={0,-1,1,0};
30typedef long long LL;
31const int inf = 0x3f3f3f3f;
32const double pi = acos(-1.0);
33const int N=1E3+7;
34int n;
35double ang[N];
36int dblcmp( double d)
37{
38return d<-eps?-1:d>eps;
39}
40struct point
41{
42double x,y;
43point(){}
44point (double _x,double _y):
45x(_x),y(_y){};
46 46
47void input()
48{
49scanf("%lf %lf",&x;,&y);
50}
51 51
52double myatan2(point p)
53{
54double res = atan2(p.y-y,p.x-x);
55return res>0?res:res+2*pi;
56}
57}p[N];
58 58
59int main()
60{
61#ifndef ONLINE_JUDGE
62freopen("in.txt","r",stdin);
63#endif
64
65while (scanf("%d",&n;)!=EOF)
66{
67if (n<=0) break;
68for ( int i = 0 ; i < n ; i++) p[i].input();
69 69
70double mx = 0;
71for ( int i = 0 ; i < n ; i++ )
72{
73int cnt = 0 ;
74for ( int j = 0 ; j < n ;j++)
75{
76if (i==j) continue;
77ang[cnt++] = p[i].myatan2(p[j]);
78}
79sort(ang,ang+cnt);
80double mn = 999999;
81for ( int j = 0 ; j < cnt-1 ; j++)
82{
83double tmp = ang[j+1]-ang[j];
84if (dblcmp(tmp-pi)>0) //直线的夹角不可能是钝角
85{
86tmp = 2*pi-tmp;
87}
88mn = min(tmp,mn);
89}
90mx = max(mn,mx);
91}
92printf("%.4fn",mx*(180.0/pi));
93 93
94}
95 95
96
97#ifndef ONLINE_JUDGE
98#endif
99fclose(stdin);
100return 0;
101}