"Convex Shell" "Hnoi 2008" "Bzoj 1007" Horizontal Visible Line

Source: Internet
Author: User

1007: [HNOI2008] Horizontal visible Line
Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 4567  Solved: 1686

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 Input

3-1 01 00 0

Sample Output

1 2

Exercises

At first glance, I think this is a half-plane, but after careful examination of the problem found that it is not so complicated, just to maintain a lower convex shell is good.

Code:

#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <algorithm>using namespace STD;#define N 50100structe{intXu,a,b;} E[n],ee[n];intn,top=0, num=0, Z[n];intIn () {intx=0;CharCh=getchar ();BOOLf=true; while(ch<' 0 '|| Ch>' 9 '){if(ch=='-') f=false;    Ch=getchar (); } while(ch>=' 0 '&& ch<=' 9 ') x=x*Ten+ch-' 0 ', Ch=getchar ();if(!f) X=-x;returnx;}BOOLCMP1 (E x,e y) {returnX.A&GT;Y.A;}BOOLCMP2 (intXintY) {returnEe[x].xu<ee[y].xu;}DoubleJiao (E x,e y) {return(Double)((Double) (Y.B-X.B)/(Double) (X.A-Y.A));}intMain () {n=in (); z[++top]=1; for(intI=1; i<=n;    i++) E[i].xu=i,e[i].a=in (), E[i].b=in (); Sort (e+1, e+n+1, CMP1); for(intI=1; i<=n; i++) {if(e[i].a!=ee[i-1].A) Ee[++num]=e[i];Else if(e[i].b>ee[num].b) ee[num]=e[i]; } for(intI=2; i<=num; i++) { while(top>=2){DoubleX1=jiao (ee[z[top-1]],ee[i]);DoubleX2=jiao (Ee[z[top]],ee[i]);if(x1<=x2+1e-6) top--;Else  Break;    } z[++top]=i; } sort (z+1, z+top+1, CMP2); for(intI=1; i<=top; i++)printf("%d", Ee[z[i]].xu);return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Convex Shell" "Hnoi 2008" "Bzoj 1007" Horizontal Visible Line

Related Article

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.