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

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: [email protected]
  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 }

时间: 2024-08-09 22:02:07

hdu 3532 Max Angle(atan2的使用)的相关文章

HDU 3532 Max Angle(计算几何——极角排序)

传送门 Max Angle Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 704    Accepted Submission(s): 253 Problem Description Given many points in a plane, two players are playing an interesting game. Pl

HDU 1024 Max Sum Plus Plus --- dp+滚动数组

HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值,其中第i个子序列包括a[j], 则max(dp[m][k]),m<=k<=n 即为所求的结果 <2>初始状态: dp[i][0] = 0, dp[0][j] = 0; <3>状态转移: 决策:a[j]自己成为一个子段,还是接在前面一个子段的后面 方程: a[j]直接接在前面

[2016-03-28][HDU][1024][Max Sum Plus Plus]

时间:2016-03-28 17:45:33 星期一 题目编号:[2016-03-28][HDU][1024][Max Sum Plus Plus] 题目大意:从n个数字提取出一定数字组成m个部分,使得这个部分的总和最大 分析: dp[i][j]表示前i段计算第j个数字,dp[i][j] = max(dp[i - 1][j - 1] + a[j],dp[i][k] + a[j]); #include <algorithm> #include <cstring> #include &

HDU 3415 Max Sum of Max-K-sub-sequence 单调队列题解

本题又是一题单调队列题解. 技巧就是需要计算好前n项和Sn = a1 + a2 + ... an 这样方便处理. 记录一条单调队列,其意义是: q(head), q(head+1), ...q(tail) 其中头q(head)代表当前最佳解的起点 这样我们只需要在求某点为结尾的S[i] - S[q(head)就得到当前最佳值. 了解了单调数列,知道其中的记录意义,那么这道题就没有难度了.我也是了解这些信息之后就自己敲出代码的. 不过有些细节没写好也让我WA了几次. 最近少刷水题,而一直都是每天一

hdu 2993 MAX Average Problem (斜率优化dp入门)

MAX Average Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5855    Accepted Submission(s): 1456 Problem Description Consider a simple sequence which only contains positive integers as

hdu 3415 Max Sum of Max-K-sub-sequence(单调队列)

题目链接:hdu 3415 Max Sum of Max-K-sub-sequence 题意: 给你一串形成环的数,让你找一段长度不大于k的子段使得和最大. 题解: 我们先把头和尾拼起来,令前i个数的和为sum[i]. 然后问题变成了求一个max{sum[i]-sum[j]}(i-k<j<i) 意思就是对于每一个sum[i],我们只需要找一个满足条件的最小的sum[j],然后我们就可以用一个单调队列来维护. 1 #include<bits/stdc++.h> 2 #define F

Hdu 1024 Max Sum Plus Plus (dp)

题目链接: Hdu 1024 Max Sum Plus Plus 题目描述: 给出n个数,问m段连续子序列的和相加最大是多少? 解题思路: dp[i][j]表示把前i个元素(包括第i个),分成j段的最大和.状态转移方程就是dp[i][j] = max (dp[i-1][j] + arr[j],  max( dp[k][j-1]) + arr[j]),其中0<k<i.(第i个元素是保存在第j段,还是自己单独成段) 由于1<=n<=1000,000.n*n的数组肯定会爆炸,所以要对方程

hdu 1024 Max Sum Plus Plus(DP)

转移方程dp[i][j]=Max(dp[i][j-1]+a[j],max(dp[i-1][k] ) + a[j] ) 0<k<j 此链接中有详解点击打开链接 #include<stdio.h> #include<algorithm> #include<iostream> using namespace std; #define MAXN 1000000 #define INF 0x7fffffff int dp[MAXN+10]; int mmax[MAXN

hdu 2710 Max Factor(找最大素数)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2710 Problem Description To improve the organization of his farm, Farmer John labels each of his N (1 <= N <= 5,000) cows with a distinct serial number in the range 1..20,000. Unfortunately, he is unawa