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 ...
随机推荐
- svn升级(mac)
原文链接:http://www.jianshu.com/p/c81712ecccb8 升级前 svn版本1.7.20 升级之后 1.9.2 步骤: 1. 下载最新版svn,链接:http://www. ...
- 关于localStorage的实际应用
在客户端存储数据 HTML5 提供了两种在客户端存储数据的新方法: localStorage - 没有时间限制的数据存储 sessionStorage - 针对一个 session 的数据存储 之前, ...
- “Hello world!”团队—团队选题展示(视频展示说明)
本次博客的主要内容基本分为以下两方面: 一.视频截图展示 二.视频简要说明 博客内容展示: 视频截图1: 简要说明:这是组长在视频前期简要介绍我们这款游戏项目的内容.从可行性和需求市场方面进行了简要阐 ...
- YaoLingJump开发者日志(九)V1.1.1版本完成
跳跃吧瑶玲下载连接 百度网盘下载 介绍 Android版本升级到8.0,发现原来的图标不显示了: 百度了一下解决方案,用了该博客提供的第二种方法,修改roundIcon的内容. 可爱的图标 ...
- js图片转换为base64
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- python 查看趴下来的数据
#coding=utf-8 import re from lxml import etree import requests def requests_view(response): import w ...
- phpcms退出 提示 :退出成功0 。 的解决办法
打开/phpcms/modules/member/index.php 搜索如下代码: showmessage(L('logout_success').$synlogoutstr, $forward); ...
- hibernate.cfg.xml的详细解释
<!--标准的XML文件的起始行,version='1.0'表明XML的版本,encoding='gb2312'表明XML文件的编码方式--> < ...
- mysql学习之数据备份与恢复
该文使用mysql5.5 centos6.5 64位(本人使用rpm安装mysql,数据库的安装目录默认) 一.数据备份注意事项 读锁问题:数据库(或者某个表)一旦进行读锁操作则影响数据库的写操作所以 ...
- <hx>标签 字体自动加粗 自动换行
<hx>标签 字体自动加粗 自动换行