[HNOI2008] Horizontal visible Line

Source: Internet
Author: User

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 2Problem Solving Ideas:This is a geometric water problem, the algorithm is very simple, first according to the slope sort, sequentially processing each straight line y-kx1-b1=0 Y-kx2-b2=0 obtained two linear focal axis, we will find that the convex hull composed of straight line with the K value increment, the intersection of the left side is also incremented so with a monotone stack to maintain the line set,  If the intersection (K,J) is to the left of the intersection (I,J), the line I must be overwritten so the line I pops up the stack, and so on. AC Code:

#include <cstdio>
#include <stack>
#include <algorithm>
#define EPS 1e-8
#define MAXN 50001
using namespace Std;
typedef double D;
Class node{
Public
int num;
D k,b;
};
stack<node>q;
Node T[MAXN],H[MAXN];
BOOL CMP (const node A,CONST node B) {
Return (A.K&LT;B.K) | | ((a.k-b.k<eps) && (a.b>b.b)); Problem 1
}
BOOL Cmp2 (const node A,const node B) {
Return a.num<b.num;
}
Double Public_node (node A,node B) {
Return (B.B-A.B)/(A.K-B.K);
}
BOOL Istrue (int i) {
Node tmp=q.top (), TMP2;
Q.pop ();
if (! Q.empty ())
Tmp2=q.top ();
Else
tmp2=tmp;
Q.push (TMP);
if (Public_node (H[I],TMP2) <=public_node (TMP,TMP2))
return true;
return false;
}
int main () {
int n;
scanf ("%d", &n);
for (int i=0;i<n;++i)
scanf ("%lf%lf", &h[i].k,&h[i].b),
H[i].num=i;
Sort (h,h+n,cmp);
Q.push (H[0]);
for (int i=1;i<n;++i) {
if ((H[I].K-H[I-1].K) <eps)//Problem 2
Continue
while (Q.size () >1&&! Q.empty () &&istrue (i))
Q.pop ();
Q.push (H[i]);
}
int i=0;
while (! Q.empty ()) {
T[i++]=q.top ();
Q.pop ();
}
Sort (T,T+I,CMP2);
for (int j=0;j<i;++j)
printf ("%d", t[j].num+1);
}

Note the situation:Note in the code P1 P2, remember not to write the k,b in Node as shaping, if the write as a floating-point shape can not be used on the logical relationship is equal toCommonsense Knowledge: Two floating-point numbers can only be compared in a bad way.

[HNOI2008] Horizontal visible Line

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.