zoukankan      html  css  js  c++  java
  • UVa1342

    欧拉定理,平面图的顶点数、边数、面数分别为V,E和F,则V+F-E=2。

    在保证 线段规范正交 的情况下,求得线段交点,交点可能重复,应该再去除重复的点,求出V。

    sort()函数是要使用<运算符的

    unique()函数是要使用==运算符的

    根据所求的V,利用Onsegment()函数,求E。

    Onsegment()函数作用是:判断一个点是否在一条线段上,不包含端点!!

    所以,e的初始值应该为n,而不是0

    bool OnSegment(const Point& p, const Point& a1, const Point& a2) {
      return dcmp(Cross(a1-p, a2-p)) == 0 && dcmp(Dot(a1-p, a2-p)) < 0;
    }

    主要代码:

            for ( i = 0; i < n; ++i ) {
                scanf ( "%lf%lf", &P[i].x, &P[i].y );
                V[i] = P[i];
            }
            --n;
            int c = n, e = n;
            for ( i = 0; i < n; ++i )
                for ( j = i+1; j < n; ++j )
                    if ( SegmentProperIntersection(P[i], P[i+1], P[j], P[j+1]) )
                            V[c++] = GetLineIntersection(P[i], P[i+1]-P[i], P[j], P[j+1]-P[j]);
            sort ( V, V+c );//<
            c = unique(V, V+c) - V;//==
            //for ( i = 0; i < c; ++i ) printf ( "i=%d x=%lf y=%lf\n", i, V[i].x, V[i].y );                     
            for ( i = 0; i < c; ++i )
                for ( j = 0; j < n; ++j )
                    if ( OnSegment(V[i], P[j], P[j+1]) ) ++e;
            //printf ( "e=%d\n", e );
            printf ( "Case %d: There are %d pieces.\n", cases++, e+2-c );
  • 相关阅读:
    7zip 自解压安装程序
    修改当前启动菜单项的HyperVisorLaunchType
    VMware 虚拟镜像转 Hyper-V(Win10/2016)
    旋转基础知识
    变换及移动基础知识
    文字及排版章末小结
    文字排版相关
    文字变形及封套扭曲
    LinQ学习笔记.
    PHP笔记-PHP中Web Service.
  • 原文地址:https://www.cnblogs.com/Accoral/p/3138558.html
Copyright © 2011-2022 走看看