LA 3263 欧拉定理
来源:互联网 发布:网络维修招聘 编辑:程序博客网 时间:2024/06/04 20:57
#include<cstdio>#include<cmath>#include<algorithm>using namespace std;const double eps = 1e-10;int dcmp(double x) { if(fabs(x) < eps) return 0; else return x < 0 ? -1 : 1;}struct Point { double x, y; Point(double x=0, double y=0):x(x),y(y) { }};typedef Point Vector;Vector operator + (const Vector& A, const Vector& B) { return Vector(A.x+B.x, A.y+B.y); }Vector operator - (const Point& A, const Point& B) { return Vector(A.x-B.x, A.y-B.y); }Vector operator * (const 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);}bool operator == (const Point& a, const Point &b) { return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0;}double Dot(const Vector& A, const Vector& B) { return A.x*B.x + A.y*B.y; }double Cross(const Vector& A, const Vector& B) { return A.x*B.y - A.y*B.x; }Point GetLineIntersection(const Point& P, const Vector& v, const Point& Q, const Vector& w) { Vector u = P-Q; double t = Cross(w, u) / Cross(v, w); return P+v*t;}bool SegmentProperIntersection(const Point& a1, const Point& a2, const Point& b1, const Point& b2) { double c1 = Cross(a2-a1,b1-a1), c2 = Cross(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(const Point& p, const Point& a1, const Point& a2) { return dcmp(Cross(a1-p, a2-p)) == 0 && dcmp(Dot(a1-p, a2-p)) < 0;}const int maxn = 300 + 10;Point P[maxn], V[maxn*maxn];int main() { int n, kase = 0; while(scanf("%d", &n) == 1 && n) { for(int 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(int i = 0; i < n; i++) for(int 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(int i = 0; i < c; i++) for(int j = 0; j < n; j++) if(OnSegment(V[i], P[j], P[j+1])) e++; printf("Case %d: There are %d pieces.\n", ++kase, e+2-c); } return 0;}
书上的代码:
欧拉定理:
设平面图的顶点数 V ,边数 E ,面数 F ,则 F = E+2-V
分析:
1:算出顶点数,包括交点,有可能三条线段交于一点,需要去重。
2:算出线段数,如果原来的线段新增加一个点,那么一条线段一为二,所以一条线段每新增一个点就多出一条线段。
即可
0 0
- LA 3263 欧拉定理
- LA 3263 (欧拉定理)
- LA-3263-计算几何,欧拉定理
- LA 3263 - That Nice Euler Circuit 欧拉定理
- LA 3263 That Nice Euler Circuit 欧拉定理 -
- 直线交点,欧拉定理,计算几何(好看的一笔画,LA 3263)
- LA 3236 That Nice Euler Circuit(欧拉定理)
- LA 6263 The Dragon and the knights 平面划分 ,欧拉定理
- 费马小定理&&欧拉定理
- 威尔逊定理,费马小定理,欧拉定理
- 欧拉定理
- 欧拉定理证明
- 欧拉定理
- 【数论】欧拉定理
- 欧拉定理
- 欧拉定理
- 欧拉定理
- 欧拉定理
- Oracle 完全卸载步骤
- PHP/Java Bridge 实例 | PHP 调用 Java 实例
- Unity3D使用经验总结 优点篇
- 在命令行中执行python,提示提示No module named "xxx"
- java static相关
- LA 3263 欧拉定理
- BIAQ论文一览
- BufferedInputStream和BufferedOutputStream类
- spring mvc 返回json的两种方式
- subject
- Java程序员应该知道的10个调试技巧
- test
- 程序员书籍推荐
- iOS开发网络数据之AFNetworking使用