UVALA 3263 That Nice Euler Circuits(欧拉定理,判断线段相交)
来源:互联网 发布:processing是什么软件 编辑:程序博客网 时间:2024/06/07 06:35
解题思路:
欧拉定理: 设平面图的顶点数,边数和面数分别为V,E, F则 V + F - E = 2;
本题要求平面数,即 F = E + 2 - V;
因此只需要求出顶点数和边数。顶点数除了输入的顶点还包括两条线段相交的交点,同样如果三点共线,则原来的一条边变成了两条边。
#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <algorithm>#include <cmath>#include <queue>#include <set>#include <map>#define LL long longusing namespace std;const int MAXN = 300 + 10;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); }const double eps = 1e-10;bool operator <(const Point& a, const Point& b){ return a.x < b.x || (a.x == b.x && a.y < b.y);}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 Cross(Vector A, Vector B){ return A.x * B.y - A.y * B.x;}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;}bool SegmentIntersection(Point a1, Point a2, Point b1, Point b2){ double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1); double 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;}Point P[MAXN], V[MAXN*MAXN];int main(){ int n, kcase = 1; while(scanf("%d", &n)!=EOF) { if(n == 0) break; 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(SegmentIntersection(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", kcase++, e + 2 - c); } return 0;}
0 0
- UVALA 3263 That Nice Euler Circuits(欧拉定理,判断线段相交)
- LA 3263 - That Nice Euler Circuit 欧拉定理
- uvaLive 3263 That Nice Euler Circuit 欧拉定理
- LA 3263 That Nice Euler Circuit 欧拉定理 -
- LA 3236 That Nice Euler Circuit(欧拉定理)
- poj2284 That Nice Euler Circuit(欧拉定理+枚举)
- uva 1342 - That Nice Euler Circuit(欧拉定理)
- LA 3263(p260)----That Nice Euler Circuits
- Uvalive 3263 That Nice Euler Circuit(几何欧拉定理)
- hdu 1665 That Nice Euler Circuit(欧拉定理)
- POJ 2284 That Nice Euler Circuit (欧拉定理)
- UVALive 3263 That Nice Euler Circuit 计算几何欧拉定理
- UVALive 3263 That Nice Euler Circuit 计算几何+欧拉定理
- 【UVA】1342 - That Nice Euler Circuit(几何+欧拉定理)
- HDU 1665 or UVALive 3263 || That Nice Euler Circuit (欧拉定理求面数 F = E+2-V
- LA3263 That Nice Euler Circuit 2004_Shanghai 平面上的欧拉定理
- UVA 1342 - That Nice Euler Circuit(计算几何+欧拉定理)
- 【LA3263】That Nice Euler Circuit——欧拉定理的应用
- 删除Windowns断行符^M
- Ubuntu 14.04 为 root 帐号开启 SSH 登录
- LightSwitch Load Data Quickly
- 黑马程序员——JAVA String总结
- Android开发相关的Blog推荐——跟随大神的脚步才能成长为大神
- UVALA 3263 That Nice Euler Circuits(欧拉定理,判断线段相交)
- 数塔 hdu 2391
- Android webview用户体验优化-场景恢复
- iptables防火墙添加规则
- icp/sp申请要点
- iOS 8 使用本地通知 UILocalNotification时需要注册
- PhoneGap开发环境搭建
- 简单使用Github - 2015
- Oracle中的AS和IS的不同,以及使用,两者基本上没有不同 。