LA 3263 平面划分
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 problem in that story was - let me remind you - to draw a graph on a paper without lifting your pen, and finally return to the original position. Euler proved that you could do this if and only if the (planar) graph you created has the following two properties: (1) The graph is connected; and (2) Every vertex in the graph has even degree.
Joey's Euler machine works exactly like this. The device consists of a pencil touching the paper, and a control center issuing a sequence of instructions. The paper can be viewed as the infinite two-dimensional plane; that means you do not need to worry about if the pencil will ever go off the boundary.
In the beginning, the Euler machine will issue an instruction of the form (X0, Y0) which moves the pencil to some starting position (X0, Y0). Each subsequent instruction is also of the form (X', Y'), which means to move the pencil from the previous position to the new position (X', Y'), thus draw a line segment on the paper. You can be sure that the new position is different from the previous position for each instruction. At last, the Euler machine will always issue an instruction that move the pencil back to the starting position(X0, Y0). In addition, the Euler machine will definitely not draw any lines that overlay other lines already drawn. However, the lines may intersect.
After all the instructions are issued, there will be a nice picture on Joey's paper. You see, since the pencil is never lifted from the paper, the picture can be viewed as an Euler circuit.
Your job is to count how many pieces (connected areas) are created on the paper by those lines drawn by Euler.
Input
There are no more than 25 test cases. Ease case starts with a line containing an integer N4, which is the number of instructions in the test case. The following N pairs of integers give the instructions and appear on a single line separated by single spaces. The first pair is the first instruction that gives the coordinates of the starting position. You may assume there are no more than 300 instructions in each test case, and all the integer coordinates are in the range (-300, 300). The input is terminated when N is 0.
Output
For each test case there will be one output line in the format
Case x: There are w pieces.,
where x is the serial number starting from 1.
Note: The figures below illustrate the two sample input cases.

Sample Input
5
0 0 0 1 1 1 1 0 0 0
7
1 1 1 5 2 1 2 5 5 1 3 5 1 1
0
Sample Output
Case 1: There are 2 pieces.
Case 2: There are 5 pieces. 题目大意:n个端点的一笔画,第n个端点跟第一个端点重合,它是一条闭合的曲线,求它把平面划分成多少部分。
分析:
欧拉定理:设平面的顶点数、边数、面数分别为V、E、F,则V+F-E=2。
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std; struct Point
{
double x,y;
Point(double x=,double y=):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);}
bool operator < (const Point &a,const Point &b)
{
return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
const double eps=1e-; int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x<?-:;
} 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 Length(Vector A){return sqrt(Dot(A,A));}
double Angle(Vector A,Vector B){return acos(Dot(A,B)/Length(A)/Length(B));} double Cross(Vector A,Vector B){ return A.x*B.y-A.y*B.x;} Vector Rotate(Vector A,double rad)
{
return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
} 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 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)< && dcmp(c3)*dcmp(c4)<;
} bool OnSegment(Point p,Point a1,Point a2)
{
return dcmp(Cross(a1-p,a2-p))== && dcmp(Dot(a1-p,a2-p))<;
} const int maxn=+;
Point P[maxn],V[maxn*maxn]; int main()
{
int n,icase=,i,j,e,c;
while(scanf("%d",&n)== && n)
{
icase++;
for(i=;i<n;i++)
{
scanf("%lf %lf",&P[i].x,&P[i].y);
V[i]=P[i];
}
n--;
//e为边数,c为顶点数
e=c=n;
for(i=;i<n;i++)//找两两线段规范相交的
{
for(j=i+;j<n;j++)
{
if(SegmentProperIntersection(P[i],P[i+],P[j],P[j+]))//两线段规范相交
{
V[c++]=GetLineIntersection(P[i],P[i+]-P[i],P[j],P[j+]-P[j]);
}
}
}
sort(V,V+c);
c=unique(V,V+c)-V;//不重复的顶点数量
for(i=;i<c;i++)//如果点在线段上则加一条边
{
for(j=;j<n;j++)
{
if(OnSegment(V[i],P[j],P[j+])) e++;
}
}
//欧拉定理:v+f-e=2.
printf("Case %d: There are %d pieces.\n",icase,e+-c);
}
return ;
}
LA 3263 平面划分的更多相关文章
- 简单几何(求划分区域) LA 3263 That Nice Euler Circuit
题目传送门 题意:一笔画,问该图形将平面分成多少个区域 分析:训练指南P260,欧拉定理:平面图定点数V,边数E,面数F,则V + F - E = 2.那么找出新增的点和边就可以了.用到了判断线段相 ...
- LA 3263 (平面图的欧拉定理) That Nice Euler Circuit
题意: 平面上有n个端点的一笔画,最后一个端点与第一个端点重合,即所给图案是闭合曲线.求这些线段将平面分成多少部分. 分析: 平面图中欧拉定理:设平面的顶点数.边数和面数分别为V.E和F.则 V+F- ...
- LA 3263 (欧拉定理)
欧拉定理题意: 给你N 个点,按顺序一笔画完连成一个多边形 求这个平面被分为多少个区间 欧拉定理 : 平面上边为 n ,点为 c 则 区间为 n + 2 - c: 思路: 先扫,两两线段的交点,存下来 ...
- LA 2797 平面区域dfs
题目大意:一个平面区域有n条线段,问能否从(0,0)处到达无穷远处(不穿过任何线段) 分析:若两条线段有一个端点重合,这种情况是不能从端点重合处穿过的 的.因此对每个端点延长一点,就可以避免这个问题. ...
- POJ 2284 That Nice Euler Circuit (LA 3263 HDU 1665)
http://poj.org/problem?id=2284 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&a ...
- LA 3263 /// 欧拉定理 oj21860
题目大意: n个端点的一笔画 第n个和第1个重合 即一笔画必定是闭合曲线 输出平面被分成的区域数 欧拉定理 V+F-E=2 即 点数+面数-边数=2 (这里的面数包括了外部) #include < ...
- LA 2797 (平面直线图PLSG) Monster Trap
题意: 平面上有n条线段,一次给出这n条线段的两个端点的坐标.问怪兽能否从坐标原点逃到无穷远处.(两直线最多有一个交点,且没有三线共交点的情况) 分析: 首先说明一下线段的规范相交:就是交点唯一而且在 ...
- LA 3263 欧拉定理
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- LA 3263 好看的一笔画 欧拉几何+计算几何模板
题意:训练指南260 #include <cstdio> #include <cstring> #include <algorithm> #include < ...
随机推荐
- CPP-网络/通信:POST
BOOL PostSubmit(CString strUrl,const CString&strPara, CString&strContent){ BOOL bRet=FALSE; ...
- javase(4)_数组
一.数组概述 数组可以看成是多个相同类型数据组合,对这些数据的统一管理. 数组变量属于引用类型,数组也可以看成对象,数组中的每个元素相当于该对象的成员变量. 数组中的元素可以是任意类型,包括基本类型和 ...
- javaEE(13)_jdbc框架
一.使用模板方法设计模式简化开发 模板方法设计模式,执行一个程序有很多步骤,将每次都要执行的共有的提取出来放到一个抽象父类中,变化的部分通过让子类传递参数过来或将这部分抽象为抽象方法让子类通过继承的方 ...
- Ukulele 原来你也在这里
- ios之UIProgressView
UIProgressView和UIActivityIndicator有些类似 但是不同之处在于, UIProgressView能够更加精确的反应进度 UIActivityIndicator则只能表 ...
- HDU-2544-最短路(floyd)
板子题,实验一下floyd. #include <cstdio> #include <algorithm> #include <cstring> using nam ...
- MySQL常用表结构查询语句
在我们使用数据库进行查询或者建表时,经常需要查看表结构,下面以employees数据库中的departments表为例进行表结构查询: departments表:(2列9行) +---------+- ...
- RuntimeError: Failed to init API, possibly an invalid tessdata path: E:\python36\报错
OCR:光学识别符,tesserocr是python中一个OCR识别库,是对tesseract做的一个python的 API封装,所以它的核心是tesseract 在这里我安装的版本是:tessera ...
- docker系列之基础命令-2
一.查看本地镜像 docker images 二.需要基础的镜像两种方式 1.docker pull centos 可以直接拉起镜像 2.直接用xshell导入就行,docker load -i 加 ...
- CM3中数据传输对齐/非对齐方式
在CM3中,非对齐的数据传输只发生在常规的数据传送指令中,如LDR.LDRH.LDRSH.其他指令则不支持,包括: 1.多个数据的加载.存储(LDM/STM). 2.堆栈操作PUSH.POP. 3.互 ...