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 Descriptiongiven 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.
Inputthere 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.
Outputfor 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 Input30 02 00 5-1
Sample Output90.0000
Source2010 acm-icpc multi-university Training Contest (Ten)--host by HEU
Test instructions is saying. First select a point a, then choose two points b,c. So that each a corresponds to the minimum angle b-a-c maximum. We can enumerate each point, and then find the angle of the point and all the other points, and after sorting found a set of adjacent difference of the smallest, recorded as MN and then for each point to get MN, record the largest one, is the answer. What's the angle?
atan2 (y,x) is a good thing.
atan2 (y,x) represents the angle of the point (0,0) to (x, y) of the ray and the positive direction of the axis, ranging from-pi to pi (excluding-pi) .
we can handle the next turning angle between 0 and 2*PI.
It is also important to note that the angle of the line cannot be obtuse. So if the answer is obtuse, remember to fill it. 1 A, happy.
1 /*************************************************************************2 > File name:code/hdu/3552.cpp3 > Author:111qqz4 > Email: [Email protected]5 > Created time:2015 November 09 Monday 10:20 55 seconds6 ************************************************************************/7 8#include <iostream>9#include <iomanip>Ten#include <cstdio> One#include <algorithm> A#include <cmath> -#include <cstring> -#include <string> the#include <map> -#include <Set> -#include <queue> -#include <vector> +#include <stack> -#include <cctype> + #defineFST First A #defineSEC Second at #defineLson l,m,rt<<1 - #defineRson m+1,r,rt<<1|1 - #defineMS (A,X) memset (A,x,sizeof (a)) - using namespacestd; - Const DoubleEPS = 1e-8; - Const intdx4[4]={1,0,0,-1}; in Const intdy4[4]={0,-1,1,0}; -typedefLong LongLL; to Const intINF =0x3f3f3f3f; + Const DoublePI = ACOs (-1.0); - Const intn=1e3+7; the intN; * DoubleAng[n]; $ intDBLCMP (Doubled)Panax Notoginseng { - returnd<-eps?-1:d >EPS; the } + struct Point A { the Doublex, y; + Point () {} -Point (Double_x,Double_y): $ x (_x), Y (_y) {}; $ - voidinput () - { thescanf"%LF%LF",&x,&y); - }Wuyi the Doublemyatan2 (point P) - { Wu Doubleres = atan2 (p.y-y,p.x-x); - returnRes>0? res:res+2*Pi; About } $ }p[n]; - - intMain () - { A #ifndef Online_judge +Freopen ("In.txt","R", stdin); the #endif - $ while(SCANF ("%d", &n)! =EOF) the { the if(n<=0) Break; the for(inti =0; I < n; i++) P[i].input (); the - DoubleMX =0; in for(inti =0; I < n; i++ ) the { the intCNT =0 ; About for(intj =0; J < N; j + +) the { the if(I==J)Continue; theang[cnt++] =p[i].myatan2 (P[j]); + } -Sort (ang,ang+CNT); the DoubleMN =999999;Bayi for(intj =0; J < cnt-1; J + +) the { the DoubleTMP = ang[j+1]-Ang[j]; - if(DBLCMP (TMP-PI) >0)//the angle of the line cannot be obtuse. - { theTMP =2*pi-tmp; the } theMN =min (tmp,mn); the } -MX =Max (MN,MX); the } theprintf"%.4f\n", mx* (180.0/pi)); the 94 } the the the #ifndef Online_judge98 #endif About fclose (stdin); - return 0;101}
View Code
HDU 3532 Max Angle (for atan2 use)