您的位置:首页 > 其它

hdu 3532 Max Angle(atan2的使用)

2015-11-09 11:09 344 查看

Max Angle

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


[align=left]Problem Description[/align]
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.

[align=left]Input[/align]
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.

[align=left]Output[/align]
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.

[align=left]Sample Input[/align]

3
0 0
2 0
0 5
-1

[align=left]Sample Output[/align]

90.0000

[align=left]Source[/align]
2010 ACM-ICPC Multi-University Training Contest(10)——Host by HEU

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

/*************************************************************************
> File Name: code/hdu/3552.cpp
> Author: 111qqz
> Email: rkz2013@126.com
> Created Time: 2015年11月09日 星期一 10时20分55秒
************************************************************************/

#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<stack>
#include<cctype>
#define fst first
#define sec second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;
const double eps = 1E-8;
const int dx4[4]={1,0,0,-1};
const int dy4[4]={0,-1,1,0};
typedef long long LL;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const int N=1E3+7;
int n;
double ang
;
int dblcmp( double d)
{
return d<-eps?-1:d>eps;
}
struct point
{
double x,y;
point(){}
point (double _x,double _y):
x(_x),y(_y){};

void input()
{
scanf("%lf %lf",&x,&y);
}

double myatan2(point p)
{
double res = atan2(p.y-y,p.x-x);
return res>0?res:res+2*pi;
}
}p
;

int main()
{
#ifndef  ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif

while (scanf("%d",&n)!=EOF)
{
if (n<=0) break;
for ( int i = 0 ; i < n ; i++) p[i].input();

double mx = 0;
for ( int i = 0 ; i < n ; i++ )
{
int cnt = 0 ;
for ( int j = 0 ; j < n ;j++)
{
if (i==j) continue;
ang[cnt++] = p[i].myatan2(p[j]);
}
sort(ang,ang+cnt);
double mn = 999999;
for ( int j = 0 ; j < cnt-1 ; j++)
{
double tmp = ang[j+1]-ang[j];
if (dblcmp(tmp-pi)>0)   //直线的夹角不可能是钝角
{
tmp = 2*pi-tmp;
}
mn = min(tmp,mn);
}
mx = max(mn,mx);
}
printf("%.4f\n",mx*(180.0/pi));

}

#ifndef ONLINE_JUDGE
#endif
fclose(stdin);
return 0;
}


View Code

[align=left] [/align]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: