HDU 3532 Max Angle (Computational geometry-polar order)

Source: Internet
Author: User

Portal

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, and both players is playing an interesting game.

Player1 selects one point A as the vertex of A angle. Then Player2 selects, other, Points B and C. A, B and C is 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 is many test cases. In each test case, the first line was an integer n (3 <= n <= 1001), and which is the number of points on the plane. Then there is n lines. Each contains and floating number x, Y, Witch is the coordinate of a 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 is accurated up to 4 demicals.
Sample Input




-1

Sample Output
90.0000


Main topic:
The plane has n Point, there are now two players, Player 1 Select a point A , Player 2 Select two points B And c Span style= "Display:inline-block; width:0px; Height:2.616em; " > , these three points 22 is not the same, then the three points constitute an angle b-a-c, Player 1 think to make this corner as large as possible, player 2 want to make this corner as small as possible, and then the Player 1 point of view, output the maximum angle.
Problem Solving Ideas:
This topic is enumeration, first we let the Player 1 first pick a point, and then start to enumerate the remaining two points but this is time-out, then we have to consider how to find this angle, it must be the Player 1 selected point and other points of the slope, and then we can run two loops, the first cycle is to enumerate the players 1 need points, Then the second cycle enumerates the points that the player 2 needs, first we calculate the slope, and then we calculate the X axis of the angle, and then sort, the adjacent angle to take the smallest to reach the goal of the Player 2, and then in the smallest inside find the maximum value, output maximum value on the line.
< Span class= "Mrow" id= "mathjax-span-2431" >m y Span style= "Display:inline-block; width:0px; Height:2.616em; " > Code :

/**2016-08-04 Morning Author:itakmotto: Today I want to go beyond yesterday's me, tomorrow I want to surpass today's me, to create better code as the goal, constantly surpass oneself. **/#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <algorithm>#include <set>using namespace STD;typedef Long LongLL;typedef unsigned Long LongULL;Const intINF =1e9+5;Const intMAXN =1e6+5;Const intMOD =1e9+7;Const DoubleEPS =1e-7;Const DoublePI =ACOs(-1);structpoint{Doublex, y;} P[MAXN];DoubleCross (Point A, point B, point C) {return(b.x-a.x) * (C.Y-A.Y)-(B.Y-A.Y) * (c.x-a.x);}DoubleDis (point A, point B) {return(a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y);}DoubleNUM[MAXN];intMain () {intN while(~scanf("%d", &n)) {if(N <=0) Break; for(intI=0; i<n; i++)scanf("%LF%LF", &AMP;P[I].X,&AMP;P[I].Y);DoubleAns =0; for(intI=0; i<n; i++) {intsum =0;DoubleMin =5211314; for(intj=0; j<n; J + +) {if(i = = j)Continue;Doublexx = p[j].x-p[i].x;Doubleyy = P[j].y-p[i].y; Num[sum] =atan2(YY,XX)/pi* the;// /Point (YY,XX) and X-axis angle                if(Num[sum] <0) Num[sum] + = the;/// guaranteed to be positivesum++; } sort (num, num+sum);DoubleTMP =0; for(intj=1; j<sum; J + +) {tmp = num[j]-num[j-1];/// adjacent cornermin = min (tmp, min);// min value} TMP = the-num[sum-1] + num[0];            min = min (tmp, min);        ans = max (ans, Min); }printf("%.4lf\n", ans); }return 0;}

HDU 3532 Max Angle (Computational geometry-polar order)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.