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 ...
随机推荐
- [leetcode-738-Monotone Increasing Digits]
Given a non-negative integer N, find the largest number that is less than or equal to N with monoton ...
- HDU 2491 Priest John's Busiest Day(贪心)(2008 Asia Regional Beijing)
Description John is the only priest in his town. October 26th is the John's busiest day in a year be ...
- Thunder团队第六周 - Scrum会议3
Scrum会议3 小组名称:Thunder 项目名称:i阅app Scrum Master:李传康 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传 ...
- Python 零碎信息-基础 01
1. """ 可以插入多行文字. print """ abC 123' 456''" #单引号, 双引号, 也没有关系 " ...
- TCP系列21—重传—11、TLP
一.介绍 Tail Loss Probe (TLP)是同样是一个发送端算法,主要目的是使用快速重传取代RTO超时重传来处理尾包丢失场景.在一些WEB业务中,如果TCP尾包丢失,如果依靠RTO超时进行重 ...
- Unity3d学习日记(二)
跟着教程做让背景可以滚动起来并添加了背景的粒子特效,加入了敌机. ctrl攻击,↑↓←→移动,Game Over后按R重新开始游戏. Space Shooter游戏地址:http://ya ...
- 利用Fiddler,解密wireshark抓的HTTPS包
背景介绍 HTTPS加密方式介绍 浏览器-->SSL Client Hello(我支持这些加密方式)-->服务器 浏览器<-SLL Server Hello(就用这种加密,然后下面是 ...
- 统计VS2013中有效行数
将鼠标放在解决方案处,按下ctrl+shift+F b*[^:b#/]+.*$(带前面的using)^b*[^:b#/]+.*$
- java 字符串—数字常用处理
// 判断一个字符串是否都为数字 public boolean isDigit(String strNum) { return strNum.matches("[0-9]{1,}" ...
- maven Tomcat idea 热部署
1.首先得有maven项目 2.配置tomcat,可以访问页面管理项目 修改: /conf/tomcat-users.xml <role rolename="manager-gui&q ...