POJ 2653 Pick-up STICKS: Compute geometry for segment intersections

Source: Internet
Author: User
Tags final printf

POJ 2653:http://poj.org/problem?id=2653

The idea is very simple, that is, on the ground in order to sprinkle a pair of sticks, to see how many are finally pressed, the output is not pressed the number of the stick. A bit of a pit is not clear how to calculate the stick, also do not know whether the norms intersect ... And I judged it, including the endpoint overlap and partial intersection.

Train of thought: first I want to traverse from the back, to find each side, to see whether he was pressed to the edge before, if the pressure to the previous change mark, the final statistics are not marked, but tle ... Can only start looking from the front, traversing each edge is the back of the pressure over, the pressure on the direct break, if all did not press, save this edge, the final output.

int n;
   
struct point {double x, y;}; struct Line {point A, B;}
   
L[100010];
   
int ans[100010];
   
Double Xmult (Point P1, point P2, point P) {return (p1.x-p.x) * (P2.Y-P.Y)-(p2.x-p.x) * (P1.Y-P.Y);}
   
Three points collinear int dots_inline (point p1,point p2,point p3) {return zero (Xmult (P1,P2,P3));} Two points on the same side of the line, points on the line return 0//More Highlights: Http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/int Same_side (Point
   
P1,point p2,line L) {return Xmult (l.a,p1,l.b) *xmult (l.a,p2,l.b) >eps;} Whether the sentencing point is on a segment, including the endpoint int dot_online_in (Point p,line L) {return zero (Xmult (p,l.a,l.b)) && (l.a.x-p.x) * (l.b.x-p.x) &L
t;eps&& (L.A.Y-P.Y) * (L.B.Y-P.Y) <eps; ///the intersection of two segments, including endpoints and partially coincident int intersect_in (line U,line v) {if (!dots_inline (U.A,U.B,V.A) | |!
    Dots_inline (U.A,U.B,V.B)) return!same_side (u.a,u.b,v) &&!same_side (v.a,v.b,u); Return dot_online_in (u.a,v) | | Dot_online_in (u.b,v) | | Dot_online_in (v.a,u) | |
Dot_online_in (V.b,u);
  } void Solve () {  while (~SCANF ("%d", &n) && N) {for (int i = 0; i < n; ++i) {scanf ("%lf%lf
        %lf%lf ", &l[i].a.x, &l[i].a.y, &l[i].b.x, &AMP;L[I].B.Y);
        int t = 0;
            for (int i = 0; i < n; ++i) {bool flag = true;
                    for (int j = i+1; j < n; ++j) {if (intersect_in (l[i), L[j]) {
                    Flag = false;
                Break
            } if (flag) {ans[t++] = i+1;
        } printf ("Top sticks:");
        for (int i = 0; i < t-1 ++i) {printf ("%d,", ans[i]);
    printf ("%d.\n", N); }
}

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.