The HDU 1147 pick-up sticks line segment is used to determine the intersection. Violent search

Source: Internet
Author: User

// In Fact, I did it when I first encountered this problem, but I couldn't find the template with the intersection of line segments, which really left me speechless ..
// Realize the importance of the template ..
/***********************************
The first brute-force attack is enough.
If the two line segments overlap, filter the first line.
Determine the size of the template directly pasted by the intersection of line segments...
***********************************/
# Include <iostream>
# Include <cstdio>
# Include <cstring>

Using namespace STD;

Const int maxn = 100000 + 5;
Const double EPS = 1e-10;

Struct point
{
Double X, Y;
};

Point P [maxn], B [maxn];
Bool ans [maxn];

Double min (double A, double B)
{
Return a <B? A: B;
}

Double max (double A, double B)
{
Return A> B? A: B;
}

Bool inter (point a, point B, point C, point D)
{
If (min (A. X, B. X)> MAX (C. x, D. x) |
Min (A. Y, B. y)> MAX (C. Y, D. Y) |
Min (C. x, D. X)> MAX (A. X, B. x) |
Min (C. Y, D. Y)> MAX (A. Y, B. y ))
Return 0;

Double H, I, J, K;

H = (B. x-a.x) * (C. y-a.y)-(B. y-a.y) * (C. x-a.x );
I = (B. x-a.x) * (D. y-a.y)-(B. y-a.y) * (D. x-a.x );
J = (D. x-c.x) * (A. y-c.y)-(D. y-c.y) * (A. x-c.x );
K = (D. x-c.x) * (B. y-c.y)-(D. y-c.y) * (B. x-c.x );

Return H * I <= EPS & J * k <= EPS;
}

int main ()
{
int N, I, j;
int res [maxn];
while (CIN> N, N)
{
memset (ANS, 0, sizeof (ANS);
for (I = 0; I
{
CIN> P [I]. x> P [I]. y> B [I]. x> B [I]. y;
}

For (I = 0; I <n; I ++)
{
For (j = I + 1; j <n; j ++)
{
If (Inter (P [I], B [I], p [J], B [J])
{
Ans [I] = 1;
Break; // timeout when break is not added...
}
}
}
Int Ct = 0;
Cout <"top sticks :";
For (I = 0; I <n; I ++)
If (! Ans [I])
Res [cT ++] = I + 1;
For (I = 0; I <CT-1; I ++)
Cout <res [I] <",";
Cout <res [CT-1] <"." <Endl;
}
Return 0;
}

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.