Bzoj 1007: [HNOI2008] Horizontal visible linear stack/computational geometry

Source: Internet
Author: User

1007: [HNOI2008] Horizontal visible line Time limit:1 Sec Memory limit:162 MB Topic Connection

http://www.lydsy.com/JudgeOnline/problem.php?id=1007

The Description has 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. Inputthe first behavior N (0 < n < 50000), the next n-line input Ai,biOutputFrom small to large output visible line number, 22 is separated by a space, the last number must also have a space behindSample Input 3
-1 0
1 0
0 0 Sample Output1 2HINT

Exercises

First we sort by the slope from big to small, then we optimize for a heap

If you want to insert a straight line, K the biggest line and K minimum will not cover the back, only the middle of the line is pressed

So let's just judge it and then keep updating it.

The specific decision is to look at the slope of the small line and slope in the middle of the line, the slope of the small line and the slope of a large line, the size of the two X coordinate to compare, then you can ~

Code:

//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 50001#defineMoD 10007#defineEPS 1e-9//const int INF=0X7FFFFFFF; //infinitely LargeConst intinf=0x3f3f3f3f;/**///**************************************************************************************structnode{Doublex, y; intID;};BOOLCMP (node C,node d) {returnC.x>d.x;}DoubleKiss (node A,node b) {return(b.y-a.y+0.0)/(a.x-b.x+0.0);} Node A[MAXN],AA[MAXN];ints[maxn];inline ll Read () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}BOOLCMP2 (intCintd) {    returna[c].id<a[d].id;}intMain () {intN; CIN>>N;  for(intI=1; i<=n;i++) {cin>>aa[i].x>>aa[i].y; Aa[i].id=i; } sort (AA+1, aa+n+1, CMP); intm=0;  for(intI=1; i<=n;i++)    {        if(aa[i].x!=a[i-1].x) a[++m]=Aa[i]; Else if(aa[i].y>a[m].y) A[m].y=aa[i].y,a[m].id=aa[i].id; }    inttop=0; s[1]=1; top=1;  for(intI=2; i<=m;i++)    {         while(top>=2)        {            DoubleX1=kiss (a[s[top-1]],a[i]); DoubleX2=Kiss (A[s[top]],a[i]); if(x1<=x2+1e-6) Top--; Else                 Break; } s[++top]=i; } sort (S+1, s+top+1, CMP2);  for(intI=1; i<=top;i++) cout<<a[s[i]].id<<" "; return 0;}

Bzoj 1007: [HNOI2008] Horizontal visible linear stack/computational geometry

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.