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.

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

题目大意:

平面上有 n 个点,现在有两个玩家,玩家1选一个点 A ,玩家2选两个点 B 和 C ,这三个点两两不相同,然后这三个点组成一个夹角 B-A-C,玩家1想想让这个角尽可能大,玩家2想让这个角尽可能小,然后以玩家1的角度来看,输出最大的角度。

解题思路:

这个题目就是枚举,首先我们让玩家1 先选取一个点,然后开始枚举剩下的两个点可是这样是超时的,那么我们要考虑怎么求这个夹角呢,那肯定是玩家1选的那个点与其他点的斜率,然后我们就可以跑两重循环,第一重循环是枚举玩家1需要的点,然后第二重循环枚举玩家2 需要的点,首先我们计算斜率,然后计算与 X 轴的夹角,然后排序,相邻的夹角取最小的就达到了玩家2的目的,然后在最小的里面找最大值,输出最大值就行了。

My Code:

/**
2016 - 08 - 04 上午
Author: ITAK

Motto:

今日的我要超越昨日的我,明日的我要胜过今日的我,
以创作出更好的代码为目标,不断地超越自己。
**/

#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;
}
时间: 2024-10-06 10:16:33

HDU 3532 Max Angle(计算几何——极角排序)的相关文章

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. Player

[POJ2007]Scrambled Polygon(计算几何 极角排序)

题目链接:http://poj.org/problem?id=2007 题意:给出凸包和起点,逆序输出. 极角排序可以用反三角函数求出角度,按照角度排序.也可以用叉乘来做.注意题目说给定第一个数据是0,0,这是凸包的起点,数据中有在x轴负半轴的数据,所以排序的时候0,0要跳过.只排1~n-1个坐标. 1 #include <algorithm> 2 #include <iostream> 3 #include <iomanip> 4 #include <cstri

hdu-5784 How Many Triangles(计算几何+极角排序)

题目链接: How Many Triangles Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 570    Accepted Submission(s): 183 Problem Description Alice has n points in two-dimensional plane. She wants to know ho

POJ Transmitters(计算几何 极角排序啊)

题目链接:http://poj.org/problem?id=1106 Description In a wireless network with multiple transmitters sending on the same frequencies, it is often a requirement that signals don't overlap, or at least that they don't conflict. One way of accomplishing thi

【计算几何+极角排序+爆ll】E. Convex

https://www.bnuoj.com/v3/contest_show.php?cid=9147#problem/E [题意] 给定n个点的坐标,可以选择其中的四个点构造凸四边形,问最多能构造多少个凸四边形? [思路] 凸四边形的个数等于C(n,4)-凹四边形的个数. 凹四边形的特点是有一个顶点被另外三个顶点围成的三角形包了起来. 所以现在的问题就是找凹四边形. 我们可以枚举每个点,作为被三角形包围的中心点o.怎么找这样包围中心点的三角形? 这样的三角形一定是在存在一条经过中心点的直线,三角

【极角排序+双指针线性扫】2017多校训练七 HDU 6127 Hard challenge

acm.hdu.edu.cn/showproblem.php?pid=6127 [题意] 给定平面直角坐标系中的n个点,这n个点每个点都有一个点权 这n个点两两可以连乘一条线段,定义每条线段的权值为线段两端点点权的乘积 现在要过原点作一条直线,要求这条直线不经过任意一个给定的点 在所有n个点两两连成的线段中,计算与这条直线有交点的线段的权值和 最大化这个权值和并输出 题目保证,给定的n个点不重合且任意两个点的连线不经过原点 [思路] 一条经过原点的直线把n个点分成两个半平面A,B 假设A中的点权

poj 1106 Transmitters (计算几何,叉积||极角排序)

Transmitters Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4817   Accepted: 2576 Description In a wireless network with multiple transmitters sending on the same frequencies, it is often a requirement that signals don't overlap, or at

HDU Always Cook Mushroom (极角排序+树状数组)

Problem Description Matt has a company, Always Cook Mushroom (ACM), which produces high-quality mushrooms. ACM has a large field to grow their mushrooms. The field can be considered as a 1000 * 1000 grid where mushrooms are grown in grid points numbe

【计算几何】【极角排序】【二分】Petrozavodsk Summer Training Camp 2016 Day 6: Warsaw U Contest, XVI Open Cup Onsite, Sunday, August 28, 2016 Problem J. Triangles

平面上给你n(不超过2000)个点,问你能构成多少个面积在[A,B]之间的Rt三角形. 枚举每个点作为直角顶点,对其他点极角排序,同方向的按长度排序,然后依次枚举每个向量,与其对应的另一条直角边是单调的,可以用一个pointer做出来,然后可以得出那些同方向的向量的区间(这个代码好像有点问题,可能会退化,最好确定了一个LL之后,对一个方向的不要重复算RR.这里如果也改成二分就比较好,复杂度不会退化).然后通过二分可以得到A使得面积在[A,B]间的有哪些(其实这个因为也是单调的,好像也没必要二分,