Title Link: xjoi-noi2015-07-b
Problem analysis
Test instructions: What is the minimum distance from the point set Q for all lines that have a point P? The distance between a line and a point set is defined as the maximum value of the distance between each point and the straight line in the dot set.
Solution: The two-point answer, for a two-minute distance, we can find the range of available polar angles for each of the points, and then determine the N-point range of the polar angle is not handed.
It sounds very simple. As a result I found the details very troublesome.
Because the range of the polar angle is annular, if it is confined within the range of [-pi, Pi], the polar range of the line spanning-pi = pi is difficult to handle.
Then two rings on the range of the intersection may be two paragraphs, is also difficult to deal with.
Learn how God Ben, for each polar range, on the left end of the last 1, the right end of a 1, and then if a position is contained by n intervals, then this position is prefixed with N.
Very harmonious, it seems that the problem has been solved ... However, I find that there are some details that God's Ben do not understand.
For example, the range may exceed [-pi, PI] .... But I have no idea ... Let's just remember how to handle this.
According to God Ben Code after writing or TLE 2 points, and finally changed the Eps so that the two-point reduction of some, finally over.
and keep 3 decimal places down, I write this way printf ("%.3f\n", Ans-0.0005); You'll lose 1 points in WA.
This writes ANSN = (int) (ANS * 1000); printf ("%d.%0 3d\n ", ansn/1000, ansn% 1000); To AC.
Code
#include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> #include <cstring > #include <algorithm>using namespace std; #define Vector point#define PI 3.14159265358979inline void Read_int ( int &num) {char c = getchar (); bool Neg = False;while (c < ' 0 ' | | c > ' 9 ') {if (c = = '-') Neg = True;c = GetChar (); }num = C-' 0 '; c = GetChar (); while (c >= ' 0 ' && C <= ' 9 ') {num = num * + C-' 0 '; c = GetChar ();} if (Neg) Num =-num;} typedef double Lf;inline LF Gmin (lf A, LF b) {return a < b? A:b;} Inline LF Gmax (lf A, LF b) {return a > b a:b;} Inline LF SQR (lf x) {return x * x;} Const LF EPS = 1e-6;const int MAXN = 111111 + 5;int N, Top, Tot; LF DIS[MAXN], ta[maxn];struct es{lf pos;int num;es () {}es (LF a, int b) {Pos = A; Num = b;}} EQ[MAXN * 4];inline bool Cmp (es e1, es E2) {return e1. Pos < E2. Pos;} struct POINT{LF x, y; Point () {}point (lf A, LF b) {x = A; y = b;} void Read () {int A, B; Read_int (a); Read_int (b); x = (LF) A; y = (LF) b;}} Px, P[maxn];inline LF Dis (Point p1, point p2) {return sqrt (SQR (p1.x-p2.x) + SQR (P1.Y-P2.Y));} BOOL Check (LF D) {LF L, r, T; Top = 0; Tot = n;for (int i = 1; I <= n; ++i) {if (Dis[i] <= d) {--tot;continue;} t = ASIN (D/DIS[I]); l = ta[i]-t;r = ta[i] + t; Eq[++top] = ES (l, 1); Eq[++top] = es (r,-1), if (Ta[i] > 0) {eq[++top] = es (L-PI, 1); Eq[++top] = ES (R-pi,-1);} Else{eq[++top] = ES (L + PI, 1); Eq[++top] = ES (R + PI,-1);}} if (Top = = 0) return true;int Cnt = 0;sort (eq + 1, eq + Top + 1, CMP); for (int i = 1; I <= Top; ++i) {Cnt + eq[i]. Num;if (Cnt = = Tot) return true;} return false;} int main () {scanf ("%d", &n); Px.read (); for (int i = 1; I <= n; ++i) {p[i]. Read ();d is[i] = Dis (p[i], Px); Ta[i] = atan2 (p[i].y-px.y, p[i].x-px.x);} LF L, R, Mid, ans;l = 0; R = 2000000;while (r-l >= Eps) {mid = (L + R)/2.0;if (Check (mid)) {Ans = Mid;r = Mid-eps;} else L = mid + Eps;} int ANSN = (int) (ANS *);p rintf ("%d.%0 3d\n ", ansn/1000, ansn%); return 0;}
[Xjoi NOI02015 training question 7] B Line Line "two points"