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. POJ 2177 Ghost Busters(三维几何)

    Description The famous Ghost Busters team has decided to upgrade their Ectomobile (aka Ecto-1) with ...

  2. js随机数算法

    function rnd( seed ){ seed = ( seed * 9301 + 49297 ) % 233280; //为何使用这三个数? return seed / ( 233280.0 ...

  3. 九度oj 题目1495:关键点

    题目描述: 在一个无权图中,两个节点间的最短距离可以看成从一个节点出发到达另一个节点至少需要经过的边的个数. 同时,任意两个节点间的最短路径可能有多条,使得从一个节点出发可以有多条最短路径可以选择,并 ...

  4. 硬盘引导扇区、多分区图、不通硬盘的LINUX逻辑分区数量

    主要启动记录区(Master Boot Record,MBR):可以安装开机管理程序的地方,有446byte 分割表(Paritition table):记录整块硬盘分割的状态,有64bytes 下面 ...

  5. django为model设置表名

    class redis_data(models.Model):     class Meta:         db_table='redis_data'     key=models.CharFie ...

  6. 统一日志系统 Log4Net/ExceptionLess

    一.   写在前面 本文Log4Net介绍了基础的方式,大数据量生产环境不能使用,中等日志量请日志单库. 希望爱技术的你不要错过exceptionless和ELK 第四节开始简单配置大牛们推荐的了Ex ...

  7. Python 时间推进器-->在当前时间的基础上推前n天 | CST时间转化标准日期格式

    由于公司任务紧迫,好久没有在园子里写自己的心得了,今天偷个闲发表点简单的代码块,在开源的时代贡献微薄力量.话不多说,直接上代码块: ]) m = ]) d = ]) the_date = dateti ...

  8. 每个zone的low memory是怎么计算出来的

    内核都是试图让活动页和不活动页的数量均衡 在分配内存时每次都会唤醒wakeup_swapd,这个函数会在 现在是不是已经没有全局的LRU表了?已经都变成per cgroup级别的LRU表了吗? ina ...

  9. KeyPress 和KeyDown 、KeyPress之间的区别

    虽然从字面理解, KeyDown是按下一个键的意思, 但实际上二者的根本区别是, 系统由KeyDown返回键盘的代码, 然后由TranslateMessage函数翻译成成字符, 由KeyPress返回 ...

  10. Redis架构演变与redis-cluster群集读写方案

    导言 redis-cluster是近年来redis架构不断改进中的相对较好的redis高可用方案.本文涉及到近年来redis多实例架构的演变过程,包括普通主从架构(Master.slave可进行写读分 ...