简单几何(求划分区域) LA 3263 That Nice Euler Circuit

题目传送门

题意:一笔画,问该图形将平面分成多少个区域

分析:训练指南P260,欧拉定理:平面图定点数V,边数E,面数F,则V + F - E =  2。那么找出新增的点和边就可以了。用到了判断线段相交,求交点,判断点在线上

/************************************************
* Author        :Running_Time
* Created Time  :2015/10/22 星期四 09:10:09
* File Name     :LA_3263.cpp
 ************************************************/

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 300 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
struct Point    {
    double x, y;
    Point (double x=0, double y=0) : x (x), y (y) {}
};
typedef Point Vector;
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;
}
int dcmp(double x)  {
    if (fabs (x) < EPS) return 0;
    else    return x < 0 ? -1 : 1;
}
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);
}
bool operator == (const Point &a, const Point &b)   {
    return dcmp (a.x - b.x) == 0 && dcmp (a.y - b.y) == 0;
}
double length(Vector A) {
    return sqrt (dot (A, A));
}
Point point_inter(Point p, Vector V, Point q, Vector W)    {
    Vector U = p - q;
    double t = cross (W, U) / cross (V, W);
    return p + V * t;
}
Point point_proj(Point p, Point a, Point b)   {
    Vector V = b - a;
    return a + V * (dot (V, p - a) / dot (V, V));
}
bool inter(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 on_seg(Point p, Point a1, Point a2)    {
    return dcmp (cross (a1 - p, a2 - p)) == 0 && dcmp (dot (a1 - p, a2 - p)) < 0;
}
Point P[N], V[N*N];

int main(void)    {
    int n, cas = 0;
    while (scanf ("%d", &n) == 1)  {
        if (!n) break;
        for (int i=0; i<n; ++i) {
            scanf ("%lf%lf", &P[i].x, &P[i].y);
            V[i] = P[i];
        }
        n--;
        int v = n, e = n;
        for (int i=0; i<n; ++i) {
            for (int j=i+1; j<n; ++j)   {
                if (inter (P[i], P[i+1], P[j], P[j+1])) {
                    V[v++] = point_inter (P[i], P[i+1] - P[i], P[j], P[j+1] - P[j]);
                }
            }
        }
        sort (V, V+v);
        v = unique (V, V+v) - V;
        for (int i=0; i<v; ++i) {
            for (int j=0; j<n; ++j) {
                if (on_seg (V[i], P[j], P[j+1]))    e++;
            }
        }
        printf ("Case %d: There are %d pieces.\n", ++cas, e + 2 - v);
    }

    return 0;
}

  

时间: 2024-08-04 18:48:04

简单几何(求划分区域) LA 3263 That Nice Euler Circuit的相关文章

平面上欧拉定理:poj 2284( LA 3263 ) That Nice Euler Circuit

3263 - That Nice Euler Circuit Time limit: 3.000 seconds Description Little Joey invented a scrabble machine that he called Euler, after the great mathematician. In his primary school Joey heard about the nice story of how Euler started the study abo

UVALive - 3263 That Nice Euler Circuit (几何)

UVALive - 3263 That Nice Euler Circuit (几何) ACM 题目地址: UVALive - 3263 That Nice Euler Circuit 题意: 给出一个点,问连起来后的图形把平面分为几个区域. 分析: 欧拉定理有:设平面图的顶点数.边数.面数分别V,E,F则V+F-E=2 大白的题目,做起来还是很有技巧的. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: LA3263.cpp * C

UVALive - 3263 - That Nice Euler Circuit (计算几何~~)

UVALive - 3263 That Nice Euler Circuit Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Little Joey invented a scrabble machine that he called Euler, after the great mathematician. In his primary sch

LA 3236 That Nice Euler Circuit(欧拉定理)

That Nice Euler Circuit Timelimit:3.000 seconds Little Joey invented a scrabble machine that he called Euler, after the great mathematician. In his primary school Joey heard about the nice story of how Euler started the study about graphs. The proble

uvalive 3263 That Nice Euler Circuit

题意:平面上有一个包含n个端点的一笔画,第n个端点总是和第一个端点重合,因此团史一条闭合曲线.组成一笔画的线段可以相交,但是不会部分重叠.求这些线段将平面分成多少部分(包括封闭区域和无限大区域). 分析:若是直接找出所有区域,或非常麻烦,而且容易出错.但用欧拉定理可以将问题进行转化,使解法变容易. 欧拉定理:设平面图的顶点数.边数和面数分别为V,E,F,则V+F-E=2. 这样,只需求出顶点数V和边数E,就可以求出F=E+2-V. 设平面图的结点由两部分组成,即原来的结点和新增的结点.由于可能出

UVALive 3263 That Nice Euler Circuit 计算几何欧拉定理

欧拉定理:P+F-E=2 That Nice Euler Circuit Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Little Joey invented a scrabble machine that he called Euler, after the great mathematician. In his primary schoo

简单几何 UVA 11178 Morley&#39;s Theorem

题目传送门 题意:莫雷定理,求三个点的坐标 分析:训练指南P259,用到了求角度,向量旋转,求射线交点 /************************************************ * Author :Running_Time * Created Time :2015/10/21 星期三 15:56:27 * File Name :UVA_11178.cpp ************************************************/ #include

HDU 4793 Collision + HDU 4798 Skycity 简单几何

HDU 4793 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4793 题意:给一个以(0,0)为圆心半径为R的圆形区域,中间放着一个(0,0)为圆心半径为Rm的圆盘,在坐标(x,y)处(严格在圆形区域外)放着一枚半径为r的硬币,运动方向和速度为(vx,vy),在运动中碰到圆盘时,会按碰撞问题反弹(圆盘是固定不动的),问硬币会在圆形区域里呆多长时间(硬币只要有一点点在圆形区域里就记为硬币在圆形区域内). 思路:首先先计算出硬币在移动过程中如果不与圆盘

hdu5365 简单几何问题

http://acm.hdu.edu.cn/showproblem.php?pid=5365 Problem Description AFA is a girl who like runing.Today,he download an app about runing .The app can record the trace of her runing.AFA will start runing in the park.There are many chairs in the park,and