UVALive-3263 That Nice Euler Circuit (几何欧拉定理)
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 (几何欧拉定理)的更多相关文章
- 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. 其 ...
- UVALive - 3263 That Nice Euler Circuit (几何)
UVALive - 3263 That Nice Euler Circuit (几何) ACM 题目地址: UVALive - 3263 That Nice Euler Circuit 题意: 给 ...
- UVALi 3263 That Nice Euler Circuit(几何)
That Nice Euler Circuit [题目链接]That Nice Euler Circuit [题目类型]几何 &题解: 蓝书P260 要用欧拉定理:V+F=E+2 V是顶点数; ...
- uvalive 3263 That Nice Euler Circuit
题意:平面上有一个包含n个端点的一笔画,第n个端点总是和第一个端点重合,因此团史一条闭合曲线.组成一笔画的线段可以相交,但是不会部分重叠.求这些线段将平面分成多少部分(包括封闭区域和无限大区域). 分 ...
- UVALive 3263: That Nice Euler Circuit (计算几何)
题目链接 lrj训练指南 P260 //==================================================================== // 此题只需要考虑线 ...
- LA 3263 That Nice Euler Circuit(欧拉定理)
That Nice Euler Circuit Little Joey invented a scrabble machine that he called Euler, after the grea ...
- 简单几何(求划分区域) LA 3263 That Nice Euler Circuit
题目传送门 题意:一笔画,问该图形将平面分成多少个区域 分析:训练指南P260,欧拉定理:平面图定点数V,边数E,面数F,则V + F - E = 2.那么找出新增的点和边就可以了.用到了判断线段相 ...
- That Nice Euler Circuit(LA3263+几何)
That Nice Euler Circuit Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu D ...
- poj2284 That Nice Euler Circuit(欧拉公式)
题目链接:poj2284 That Nice Euler Circuit 欧拉公式:如果G是一个阶为n,边数为m且含有r个区域的连通平面图,则有恒等式:n-m+r=2. 欧拉公式的推广: 对于具有k( ...
- POJ2284 That Nice Euler Circuit (欧拉公式)(计算几何 线段相交问题)
That Nice Euler Circuit Time Limit: 3000MS M ...
随机推荐
- PHP 5.6.32 增加pdo_dblib.so拓展
首先说明,php增加pdo_dblib.so拓展不需要重新编译php源文件,只需要增加dblib源包即可. 1.下载安装所需包 1.#下载 wget http://mirrors.ibiblio.or ...
- c# word 删除指定内容
1.首先简单的是获取得到的range,直接rangge.delete() 2.文本框的删除: foreach (Microsoft.Office.Interop.Word.Shape shape in ...
- 用纯css改变下拉列表select框的默认样式(转)
用纯css改变下拉列表select框的默认样式 分享到 分类 JS学习 关键字 前端 发布 kris 2015-04-01 注意 转载须保留原文链接,译文链接,作者译者等信息. 在这 ...
- ACM 第十八天
数学基础(卷积,FFT,FWT,FMT,鸽巢原理,群论,哈里亚余数,哈里亚计数定理,组合数学,LVG定理,期望DP,期望点贡献问题) 练习题: A - Necklace of Beads Beads ...
- 转 Js 跨域CORS报错 Response for preflight has invalid HTTP status code 405
转自:http://www.cnblogs.com/SilenceTom/p/6697484.html 调用接口遇到Response for preflight has invalid HTTP st ...
- 【alpha】Scrum站立会议第3次....10.18
小组名称:nice! 小组成员:李权 于淼 杨柳 刘芳芳 项目内容:约跑app(约吧--暂定) 1.任务进度 2.燃尽图 功能列表 1.登录注册 2.创建跑步计划 3.筛选跑友 4.加一起跑步的人为好 ...
- week1 技术随笔
类别c 内容c 开始时间s 结束时间e 被打断时间I 总计(min) 9.5 随笔 构建之法福后感 22:00 24:00 7 113 9.6 分析 需求分析 9:00 9:30 2 28 编码 词频 ...
- Python使用ElementTree美化XML格式
Python中使用ElementTree可以很方便的处理XML,但是产生的XML文件内容会合并在一行,难以看清楚. 如下格式: <root><aa>aatext<cc&g ...
- 完整和增量备份MySQL脚本
本文档采用mysqldump 对数据库进行备份,mysqldump 是采用SQL级别的备份机制,它将数据表导成 SQL脚本文件,在不同的 MySQL 版本之间升级时相对比较合适,这也是最常用的备份方法 ...
- SQL SERVER技术内幕之10 可编程对象
一.变量 变量用于临时保存数据值,以供在声明它们的同一批处理语句中引用.例如,以下代码先声明一个数据类型为INT的变量@i,再将它赋值为10; DECLARE @i as INT; SET @i = ...