Time limit:1 Sec Memory limit:162 MB
submit:5308 solved:1990
[Submit] [Status] [Discuss] Description
There are n linear l1,l2 on the Xoy Cartesian plane,... Ln, if the Y value is positive infinity down, you can see a sub-segment of Li, it is said that Li is visible, otherwise li is covered.
For example, for a line:
L1:y=x; L2:y=-x; L3:y=0
Then L1 and L2 are visible, and L3 are covered.
gives a line of N, expressed as a form of y=ax+b (| a|,| b|<=500000), and the N line 22 does not coincide. Find all the visible lines.
Input
The first behavior n (0 < n < 50000), the next n-line input Ai,bi
Output
From small to large output visible line number, 22 is separated by a space, the last number must also have a space behind
Sample Input3
-1 0
1 0
0 0Sample Output1 2
The following:
Sort by the slope first, then the smallest line into the stack, then processing the 2~n line, if the intersection of line I and stack[top] straight line to the left of Stack[top] and stack[top-1] straightness, then top--, the concrete can draw a few lines to simulate a bit.
1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <algorithm>6#include <cmath>7#include <queue>8#include <vector>9 using namespacestd;Ten Const Doubleeps=1e-6; One Const intmaxn=50010; A structbian{ - Doublek,b; - intID; the }STR[MAXN]; - intcmpConstBian &x1,ConstBian &x2) { - returnx1.k<x2.k| | (Fabs (X1.K-X2.K) <eps&&x1.b<x2.b); - } +InlineDoubleCROSSX (intX1,intx2) { - return(str[x2].b-str[x1].b)/(str[x1].k-str[x2].k); + } A intStack[maxn],top; at intN,ANS[MAXN]; - intMain () { -scanf"%d",&N); - for(intI=1; i<=n;i++){ -scanf"%LF%LF",&str[i].k,&str[i].b); -Str[i].id=i; in } -Sort (str+1, str+n+1, CMP); to +stack[++top]=1; - for(intI=2; i<=n;i++){ the while(top!=0){ * if(Fabs (STR[I].K-STR[STACK[TOP]].K) <eps) top--; $ if((CROSSX (stack[top-1],i) <=CROSSX (stack[top-1],stack[top]) &&top>=2)Panax Notoginsengtop--; - Else Break; the } +stack[++top]=i; A } the for(intI=1; i<=top;i++) ans[str[stack[i]].id]=1; + for(intI=1; i<=n;i++){ - if(ans[i]==1) printf ("%d", i); $ } $ return 0; -}
Bzoj 1007: [HNOI2008] Horizontal visible Line