HDU 3532 Max Angle(计算几何——极角排序)
来源:互联网 发布:python opencv图像识别 编辑:程序博客网 时间:2024/06/06 11:05
传送门
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.
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.
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
题目大意:
平面上有
解题思路:
这个题目就是枚举,首先我们让玩家1 先选取一个点,然后开始枚举剩下的两个点可是这样是超时的,那么我们要考虑怎么求这个夹角呢,那肯定是玩家1选的那个点与其他点的斜率,然后我们就可以跑两重循环,第一重循环是枚举玩家1需要的点,然后第二重循环枚举玩家2 需要的点,首先我们计算斜率,然后计算与
/**2016 - 08 - 04 上午Author: ITAKMotto:今日的我要超越昨日的我,明日的我要胜过今日的我,以创作出更好的代码为目标,不断地超越自己。**/#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <algorithm>#include <set>using namespace std;typedef long long LL;typedef unsigned long long ULL;const int INF = 1e9+5;const int MAXN = 1e6+5;const int MOD = 1e9+7;const double eps = 1e-7;const double PI = acos(-1);struct Point{ double x, y;}p[MAXN];double Cross(Point a, Point b, Point c){ return (b.x-a.x)*(c.y-a.y) - (b.y-a.y)*(c.x-a.x);}double dis(Point a, Point b){ return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}double num[MAXN];int main(){ int n; while(~scanf("%d",&n)) { if(n <= 0) break; for(int i=0; i<n; i++) scanf("%lf%lf",&p[i].x,&p[i].y); double ans = 0; for(int i=0; i<n; i++) { int sum = 0; double Min = 5211314; for(int j=0; j<n; j++) { if(i == j) continue; double xx = p[j].x - p[i].x; double yy = p[j].y - p[i].y; num[sum] = atan2(yy,xx)/PI*180;///点(yy,xx) 与 X 轴的夹角 if(num[sum] < 0) num[sum] += 360;///保证是正数 sum++; } sort(num, num+sum); double tmp = 0; for(int j=1; j<sum; j++) { tmp = num[j]-num[j-1];///相邻角 Min = min(tmp, Min);///最小值 } tmp = 360 - num[sum-1] + num[0]; Min = min(tmp, Min); ans = max(ans, Min); } printf("%.4lf\n",ans); } return 0;}
0 0
- HDU 3532 Max Angle(计算几何——极角排序)
- HDU 3532 Max Angle(计算几何——极角排序)
- hdu 3532 Max Angle
- sgu233The Greatest Angle(计算几何)
- HDU 6127 Hard challenge 计算几何 极角排序
- hdu 6127 Hard challenge (计算几何——斜率排序)
- 计算几何的排序--极角排序
- sgu233:The Greatest Angle(计算几何)
- 【CodeForces】257C - View Angle(计算几何)
- 计算几何(组合计数+向量排序)——Eureka ( HDU 5738 ) ( 2016 Multi-University Training Contest 2 1005 )
- Poj1696计算几何的叉积+极角排序+贪心
- POJ 1106 Transmitters(计算几何 极角排序啊)
- 计算几何之叉乘和极角排序
- POJ1696---Space Ant(基础计算几何:极角排序)
- POJ1696 space ant(计算几何,极角排序)
- POJ 1696 Space Ant (计算几何 + 极角排序)
- CodeForces - 257C View Angle 【极角排序】
- ACM-计算几何之Shape of HDU——hdu2108
- Scala(0)
- 《UI进化论》笔记
- Apache的prefork模式和worker模式研究
- http常见错误码总结
- 自定义View(TopBar)
- HDU 3532 Max Angle(计算几何——极角排序)
- hdu 5791 Two 二维前缀和
- Kotlin开发Android笔记8:Kotlin数据类及json解析
- ViewPager实现画廊效果
- 前端错误集
- D - 放苹果
- 网络编程之TCP
- CodeWars练习之三角数
- 数据结构实验之栈五:下一较大值(一)