Ural-1966-cycling Roads (and check collection + Sentencing line intersection)

Source: Internet
Author: User

Serie A champions: N Integrals, M Edge (1≤m < n≤200), Q: Whether all point connections (two edges intersect. The 4-point connection).

Topics Link: http://acm.timus.ru/problem.aspx?space=1&num=1966

-->> for each edge, the end points on the edge are incorporated into the collection, enumerating edges and edges. Infer whether they intersect, the points are merged into the collection, and the number of elements within the set is N.

#include <cstdio> #include <cmath>const int maxn = + 10;const Double EPS = 1e-8;struct point{double x;    Double y; Point () {} point (double x, double y): X (x), Y (y) {}} p[maxn];int N, M;int Fa[maxn], Cnt[maxn];int U[MAXN], v[maxn];typed EF point Vector; Vector operator-(vector A, vector B) {return vector (a.x-b.x, a.y-b.y);}    int dcmp (double x) {if (Fabs (x) < EPS) return 0; return x > 0? 1:-1;} Double Dot (vector A, vector B) {return a.x * b.x + a.y * B.Y;} Double Cross (vector A, vector B) {return a.x * b.y-a.y * b.x;}    BOOL Segmentproperintersection (Point-A1, Point-A2, point-B1, point-B2) {Double C1 = Cross (A2-A1, B1-A1);    Double C2 = Cross (A2-A1, B2-A1);    Double C3 = Cross (B2-B1, A1-B1);    Double C4 = Cross (b2-b1, A2-B1); Return DCMP (C1) * DCMP (C2) < 0 && dcmp (C3) * DCMP (C4) < 0;} BOOL Onsegment (point P, point A1, point A2) {return dcmp (cross (a1-p, a2-p)) = = 0 && dcmp (Dot (a1-p, A2- p)) < 0;}        void Init () {for (int i = 1; I <= n; ++i) {fa[i] = i;    Cnt[i] = 1; }}int find (int x) {return x = = Fa[x]? x: (Fa[x] = find (fa[x]));}    void Union (int x, int y) {int xroot = Find (x);    int yroot = Find (y);        if (xroot! = yroot) {Fa[yroot] = Xroot;    Cnt[xroot] + = Cnt[yroot];    }}void Read () {for (int i = 1; I <= n; ++i) {scanf ("%lf%lf", &p[i].x, &AMP;P[I].Y);        } for (int i = 0; i < m; ++i) {scanf ("%d%d", U + I, v + i);        Union (U[i], v[i]);  for (int j = 1; j <= N; ++j) {if (J! = U[i] && J! = V[i] && onsegment (P[j], P[u[i]],            P[v[i]]) {Union (J, U[i]);            }}}}void Merge () {for (int i = 0; i < m; ++i) {for (int j = i + 1; j < m; ++j) {            if (Segmentproperintersection (P[u[i]], P[v[i]], P[u[j]], P[v[j]])) {Union (U[i], u[j]); }}}}void Output () {cnt[find (1)] = = n? 

Puts ("YES"): Puts ("NO");} int main () {while (scanf ("%d%d", &n, &m) = = 2) {Init (); Read (); Merge (); Output (); } return 0;}



Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Ural-1966-cycling Roads (and check collection + Sentencing line intersection)

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.