LA 3263 Good-looking one-stroke Euler geometry + Computational Geometry template

Source: Internet
Author: User
Tags cos

Test Instructions: Training Guide 260

#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <    Cmath>using namespace Std;struct Point {double x, y; Point (Double x = 0, double y = 0): x (x), Y (y) {}};typedef point Vector; Vector operator + (vector A, vector B) {return vector (a.x+b.x, a.y+b.y);} Vector operator-(vector A, vector B) {return vector (a.x-b.x, a.y-b.y);} Vector operator * (vector A, double p) {return vector (a.x*p, a.y*p);} Vector operator/(vector A, double p) {return vector (a.x/p, a.y/p);} BOOL operator < (const point& A, const point& b) {return a.x < b.x | | (a.x = = b.x && a.y < B.Y);} Const DOUBLE EPS = 1e-10;int dcmp (double x) {if (Fabs (x) < EPS) return 0; else return x < 0? -1:1;} BOOL operator = = (const point& A, const point& b) {return dcmp (a.x-b.x) = = 0 && dcmp (a.y-b.y) = = 0 ;} Double Dot (vector A, vector B) {return a.x*b.x + a.y*b.y;} Double Length (Vector A) {return sqrt (DOT (A, a)); }double Angle (vector A, vector b) {return ACOs (Dot (A, b)/Length (a)/length (b));} Double Cross (vector A, vector B) {return a.x*b.y-a.y*b.x;} Double Area2 (Point A, Point-B, point-C) {return cross (b-a, c-a);} Vector Rotate (vector A, double rad) {return vector (A.x*cos (RAD)-A.y*sin (RAD), A.x*sin (RAD) +a.y*cos (RAD));}    Vector Normal (vector a) {double L = Length (a); Return Vector (-a.y/l, a.x/l);}    Point Getlineintersection (Point P, Vector v, point Q, vector w) {vector u = p-q;    Double T = Cross (w, u)/Cross (V, W); return P + v * t;}    Double Distancetoline (Point P, point A, point B) {Vector V1 = b-a, v2 = p-a; Return Fabs (Cross (V1,V2)/Length (v1));}    Double Distancetosegment (Point P, point A, point B) {if (a==b) return Length (P-A);    Vector v1 = b-a, v2 = p-a, V3 = p-b;    if (dcmp (Dot (v1, v2)) < 0) return Length (v2);    else if (dcmp (Dot (v1, v3)) > 0) return Length (V3); else return Fabs (cross (v1, v2))/Length (v1);} Point GetlineprOjection (Point P, point A, point B) {Vector v = b-a; return A + v * (dot (v, p-a)/dot (V, v));} BOOL Segmentproperintersection (Point-A1, Point-A2, point-B1, point-B2) {Double C1 = Cross (A2-A1, b1-a1), C2 = Cros    S (a2-a1, b2-a1), C3 = Cross (B2-B1, a1-b1), 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;}    Double Convexpolygonarea (point* p, int n) {double area = 0;    for (int i = 1; i < n-1; i++) area + = Cross (P[i]-p[0], P[i + 1]-p[0]); return AREA/2;} const int MAXN = 300 + 10; Point P[MAXN], V[MAXN*MAXN];    Point P[305],v[305*305];int Main () {int n,cas=0;        while (~SCANF ("%d", &n) &&n) {cas++;                for (int i=1;i<=n;i++) {scanf ("%lf%lf", &p[i].x,&p[i].y);       V[i]=p[i];    } n--;        int cnt=n+1; for (int i=1;i<=n;i++) for (int j=i+1;j<=n;j++) if (Segmentproperintersection (p[i],p[i+1],p[j],p[j+1        ])) v[++cnt]=getlineintersection (P[i],p[i+1]-p[i],p[j],p[j+1]-p[j]);        Sort (v+1,v+cnt+1);        int Vnum=unique (v+1,v+cnt+1)-(v+1);        for (int i=1;i<=vnum;i++)//printf ("V%d:%f%f\n", i,v[i].x,v[i].y);        int e=n;        cout<< "Ori" <<e<<endl;                  for (int i=1;i<=vnum;i++) for (int j=1;j<=n;j++) if (Onsegment (v[i],p[j],p[j+1]))       e++;        cout<< "Vnum:" <<vnum<< "E:" <<e<<endl;    printf ("Case%d:there is%d pieces.\n", cas,e+2-vnum); } return 0;//v+f-e=2;}

  

LA 3263 Good-looking one-stroke Euler geometry + Computational Geometry template

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.