https://vjudge.net/problem/UVALive-3263

平面上有一个n个端点的一笔画,第n个端点总是和第一个端点重合,因此图示一条闭合曲线。

组成一笔画的线段可以相交,但不会部分重叠,求这些线段将平面分为几部分

包括封闭区域和无限大区域

欧拉定理:平面图的顶点数V,边数E,面数F ,V+F-E=2

顶点数包含原来节点、新增节点,可能多线共点,所以还要去重

边数包含原来的边、新增的边,

判断新增边:枚举点、边,如果点在线段上(非端点处),边数+1

判断点在线段上且非端点:点与线段端点两向量的叉积=0,点积<0

(如果是端点点积=0)

#include<cmath>
#include<cstdio>
#include<algorithm> using namespace std; const double eps=1e-; struct Point
{
double x,y;
Point(double x=,double y=) : x(x),y(y) { }
bool operator == (const Point b) const
{
return fabs(x-b.x)<eps && fabs(y-b.y)<eps;
}
bool operator < (const Point b) const
{
return (x<b.x||(fabs(x-b.x)<eps && y<b.y));
}
/*Point operator = (const Point b)
{
return b;
}*/
}; typedef Point Vector; Point p[],section[]; int sumedge,sumpoint; 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); } struct Geometry
{
double Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.x;
}
double Dot(Vector A,Vector B)
{
return A.x*B.x+A.y*B.y;
}
bool OnSegment(Point p,Point a1,Point a2)
{
return dcmp(Cross(a1-p,a2-p))== && dcmp(Dot(a1-p,a2-p))<;
}
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)<;
}
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 dcmp(double x)
{
if(fabs(x)<eps) return ; return x< ? -:;
}
}; Geometry Two_dimensional; /*bool operator == (Point a,Point b)
{
return Two_dimensional.dcmp(a.x-b.x)==0 && Two_dimensional.dcmp(a.y-b.y)==0;
}
bool operator < (Point a,Point b)
{
if(Two_dimensional.dcmp(a.x-b.x)==0)
{
if(Two_dimensional.dcmp(a.y-b.y)<=0) return 1;
return 0;
}
if(Two_dimensional.dcmp(a.x-b.x)==-1) return 1;
return 0;
}*/ /*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 Two_dimensional.dcmp(a.x - b.x) == 0 && Two_dimensional.dcmp(a.y - b.y) == 0;
}*/
int main()
{
int n,k,tt=;
while(scanf("%d",&n)!=EOF)
{
if(!n) return ;
for(int i=;i<n;i++) scanf("%lf%lf",&p[i].x,&p[i].y),section[i]=p[i];
n--;
sumpoint=n; sumedge=n;
for(int i=;i<n;i++)
for(int j=i+;j<n;j++)
{
if(Two_dimensional.SegmentProperIntersection(p[i],p[i+],p[j],p[j+]))
section[sumpoint++]=Two_dimensional.GetLineIntersection(p[i],p[i+]-p[i],p[j],p[j+]-p[j]);
}
sort(section,section+sumpoint);
sumpoint=unique(section,section+sumpoint)-section;
//for(int i=0;i<sumpoint;i++) printf("%.5lf %.5lf\n",section[i].x,section[i].y);
for(int i=;i<sumpoint;i++)
for(int j=;j<n;j++)
if(Two_dimensional.OnSegment(section[i],p[j],p[j+])) sumedge++;
printf("Case %d: There are %d pieces.\n",++tt,sumedge+-sumpoint);
} }

UVALive-3263 That Nice Euler Circuit (几何欧拉定理)的更多相关文章

  1. UVAlive 3263 That Nice Euler Circuit(欧拉定理)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21363 [思路] 欧拉定理:V+F-E=2.则F=E-V+2. 其 ...

  2. UVALive - 3263 That Nice Euler Circuit (几何)

    UVALive - 3263 That Nice Euler Circuit (几何) ACM 题目地址:  UVALive - 3263 That Nice Euler Circuit 题意:  给 ...

  3. UVALi 3263 That Nice Euler Circuit(几何)

    That Nice Euler Circuit [题目链接]That Nice Euler Circuit [题目类型]几何 &题解: 蓝书P260 要用欧拉定理:V+F=E+2 V是顶点数; ...

  4. uvalive 3263 That Nice Euler Circuit

    题意:平面上有一个包含n个端点的一笔画,第n个端点总是和第一个端点重合,因此团史一条闭合曲线.组成一笔画的线段可以相交,但是不会部分重叠.求这些线段将平面分成多少部分(包括封闭区域和无限大区域). 分 ...

  5. UVALive 3263: That Nice Euler Circuit (计算几何)

    题目链接 lrj训练指南 P260 //==================================================================== // 此题只需要考虑线 ...

  6. LA 3263 That Nice Euler Circuit(欧拉定理)

    That Nice Euler Circuit Little Joey invented a scrabble machine that he called Euler, after the grea ...

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

    题目传送门 题意:一笔画,问该图形将平面分成多少个区域 分析:训练指南P260,欧拉定理:平面图定点数V,边数E,面数F,则V + F - E =  2.那么找出新增的点和边就可以了.用到了判断线段相 ...

  8. That Nice Euler Circuit(LA3263+几何)

    That Nice Euler Circuit Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu D ...

  9. poj2284 That Nice Euler Circuit(欧拉公式)

    题目链接:poj2284 That Nice Euler Circuit 欧拉公式:如果G是一个阶为n,边数为m且含有r个区域的连通平面图,则有恒等式:n-m+r=2. 欧拉公式的推广: 对于具有k( ...

  10. POJ2284 That Nice Euler Circuit (欧拉公式)(计算几何 线段相交问题)

                                                          That Nice Euler Circuit Time Limit: 3000MS   M ...

随机推荐

  1. C中文件操作的文本模式和二进制模式,到底有啥区别?

    在C中,使用fopen打开文件有两种模式:一种是文本模式,一种是二进制模式.那这两种模式之间有什么区别,是不是使用文本模式打开的文件就只能使用文本函数比如fprintf来操作,而使用二进制打开的文件就 ...

  2. 软件工程 speedsnail 第二次冲刺9

    20150526 完成任务:划线的优化,速度和谐: 遇到问题: 问题1 速度仍然不满意 解决1 未解决 明日任务: 蜗牛碰到线后速度方向的调整:(做优化)

  3. 【转】自定义(滑动条)input[type="range"]样式

    1.如何使用滑动条? 用法很简单,如下所示: <input type="range" value="0"> 各浏览器原始样式如下: Chrome:  ...

  4. Java容器之Iterator接口

    Iterator 接口: 1. 所有实现了Collection接口的容器类都有一个iterator方法用以返回一个实现了Iterator接口的对象. 2. Iterator 对象称作迭代器,用以方便的 ...

  5. 【Linux】- CentOS 7 安装.NET Core 2.1

    添加dotnet产品Feed 在安装.NET Core之前,您需要注册Microsoft产品Feed. 这只需要做一次. 首先,注册Microsoft签名密钥,然后添加Microsoft产品Feed. ...

  6. 重载和const参数

    const仅能用于在定义函数签名时,区分是为引用定义参数,还是为指针定义参数.定义基本类型type(如int等),从重载的观点来看,const int和int是相同的. const long& ...

  7. SQL SERVER 存储过程中SELECT 返回值如何赋值给变量

    今天在处理一个问题时,使用到一个存储过程,是用于更新并获取最新ID的.在使用过程中,需要获取到这个ID并赋值给变量,结果用EXEC @ID = 存储过程的方式获取失败了.具体情况如下: 为了还原整个情 ...

  8. Python十六进制转码问题

    使用Python的decode函数转码十六进制的字符串时,会出现UnicodeDecodeError: 'utf8' codec can't decode byte 0xba in position ...

  9. BZOJ3144:[HNOI2013]切糕——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=3144 看着很像网络流,但是费用流貌似无法解决这个问题,其实甚至连忽略d的情况都做不到. 最小割? ...

  10. BZOJ1823:[JSOI2010]满汉全席——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=1823 https://www.luogu.org/problemnew/show/P4171 题面 ...