【LA 3263】That Nice Euler Circuits (Shanghai 2004)(计算几何)
2018-02-09 23:07
363 查看
Description
给定一个一笔画的图形,求将平面分成了多少个部分。Solution
统计出所有的边、点(包括交点),由欧拉公式V+F=E+2V+F=E+2求得答案即可。震惊!调了一个小时的原因竟然是点积
Dot(Vector A, Vector B写错了。。
Source
/********************************************************** * Happy Spring Festival ! * Au: Hany01 * Prob: [LA3263] That Nice Euler Circuits, Shanghai 2004 * Date: Feb 9th, 2018 * Email: hany01@foxmail.com **********************************************************/ #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef vector<int> VI; #define rep(i , j) for (int i = 0 , i##_end_ = j; i < i##_end_ ; ++ i) #define For(i , j , k) for (int i = (j) , i##_end_ = (k) ; i <= i##_end_ ; ++ i) #define Fordown(i , j , k) for (int i = (j) , i##_end_ = (k) ; i >= i##_end_ ; -- i) #define Set(a , b) memset(a , b , sizeof(a)) #define SZ(a) ((int)(a.size())) #define ALL(a) a.begin(), a.end() #define pb(a) push_back(a) #define mp(a, b) make_pair(a, b) #define INF (0x3f3f3f3f) #define INF1 (2139062143) #define Mod (1000000007) #define y1 wozenmezhemecaia #ifdef hany01 #define debug(...) fprintf(stderr , __VA_ARGS__) #else #define debug(...) #endif inline void File() { #ifdef hany01 freopen("LA3263.in" , "r" , stdin); freopen("LA3263.out" , "w" , stdout); #endif } template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; } template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; } inline int read() { register char c_; register int _ , __; for (_ = 0 , __ = 1 , c_ = getchar() ; !isdigit(c_) ; c_ = getchar()) if (c_ == '-') __ = -1; for ( ; isdigit(c_) ; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48); return _ * __; } const double eps = 1e-10; const int maxn = 305, maxv = 90005; struct Point { double x, y; Point(double x = 0, double y = 0): x(x), y(y) {} }; typedef Point Vector; int dcmp(double x) { if (fabs(x) < eps) return 0; return x < 0 ? -1 : 1; } Vector operator + (Vector A, Vector B) { return Point(A.x + B.x, A.y + B.y); } Vector operator - (Vector A, Vector B) { return Point(A.x - B.x, A.y - B.y); } Vector operator * (Vector A, double p) { return Point(A.x * p, A.y * p); } Vector operator / (Vector A, double p) { return Point(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) && !dcmp(a.y - b.y); } 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), 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(Point P, Point A, Point B) { return !dcmp(Cross(A - P, B - P)) && dcmp(Dot(A - P, B - P)) < 0; } 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; } int n, e, cnt, Case; Point p[maxn], v[maxv]; int main() { File(); while (scanf("%d", &n) != EOF && n) { For(i, 1, n) scanf("%lf%lf", &p[i].x, &p[i].y), v[i] = p[i]; cnt = e = n - 1; For(i, 1, n - 1) For(j, i + 1, n - 1) 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 + 1 + cnt); cnt = unique(v + 1, v + 1 + cnt) - v - 1; For(i, 1, cnt) For(j, 1, n - 1) if (OnSegment(v[i], p[j], p[j + 1])) ++ e; printf("Case %d: There are %d pieces.\n", ++ Case, e - cnt + 2); } return 0; }
相关文章推荐
- LA 3263 - That Nice Euler Circuit(计算几何基础题目 欧拉公式)
- UVALive 3263 That Nice Euler Circuit 计算几何欧拉定理
- 简单几何(求划分区域) LA 3263 That Nice Euler Circuit
- UVALive 3263: That Nice Euler Circuit (计算几何)
- Shanghai 2004(UVaLive 3263) - That Nice Euler Circuit
- UVALive 3263 That Nice Euler Circuit(计算几何)
- LA 3263 That Nice Euler Circuit 好看的一笔画 几何问题
- LA_3263_That_Nice_Euler_Circuits_(欧拉定理+计算几何基础)
- POJ 2284 That Nice Euler Circuit (LA 3263 HDU 1665)
- POJ 2284-That Nice Euler Circuit(计算几何_欧拉定理求平面被分成的区域数)
- LA 3263 - That Nice Euler Circles(直线相交以及交点)
- UVALive - 3263 That Nice Euler Circuit (几何)
- uva That Nice Euler Circuit(计算几何 欧拉公式)
- LA 3263 That Nice Euler Circuit 欧拉定理 -
- POJ2284 That Nice Euler Circuit (欧拉公式)(计算几何 线段相交问题)
- LA 3263 That Nice Euler Circuit (2D Geometry)
- poj 2284 That Nice Euler Circuit 计算几何
- UVA 1342 - That Nice Euler Circuit(计算几何+欧拉定理)
- Uvalive 3263 That Nice Euler Circuit(几何欧拉定理)
- LA 3263 (平面图的欧拉定理) That Nice Euler Circuit