欧拉定理:

简单多面体的顶点数V、棱数E及面数F间有关系有著名的欧拉公式:V-E+F=2。

设G为任意的连通的平面图,则v-e+f=2,v是G的顶点数,e是G的边数,f是G的面数。(

证明(?)

这题的做法就是模拟画线的过程,统计出画每一条线时与之前所有线的交点,将所有交点记录下来,将每一个顶点也记录下来。然后将点去重,得到点数。然后统计每一条线上有几个点,那么这条线就被分成了点数+1段,这样得到边数。最后根据公式算出面数。

 #include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
namespace X
{
const double eps=1e-;
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y){}
};
typedef Point Vec;
Vec operator+(const Vec& a,const Vec& b)
{
return Vec(a.x+b.x,a.y+b.y);
}
Vec operator-(const Vec& a,const Vec& b)
{
return Vec(a.x-b.x,a.y-b.y);
}
Vec operator*(const double& a,const Vec& b)
{
return Vec(a*b.x,a*b.y);
}
Vec operator*(const Vec& a,const double& b)
{
return Vec(b*a.x,b*a.y);
}
Vec operator/(const Vec& a,const double& b)
{
return Vec(a.x/b,a.y/b);
}
int dcmp(double x)
//正为1,负为-1,0为0
{
if(fabs(x)<eps) return ;
return x<?-:;
}
bool operator<(const Vec& a,const Vec& b)
//人为规定的优先级
{
return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
bool operator==(const Vec& a,const Vec& b)
//判向量相等
{
return dcmp(a.x-b.x)==&&dcmp(a.y-b.y)==;
}
double dot(const Vec& a,const Vec& b)
//点积
{
return a.x*b.x+a.y*b.y;
}
double cross(const Vec& a,const Vec& b)
//叉积
{
return a.x*b.y-a.y*b.x;
}
double len(const Vec& x)
//向量长度
{
return sqrt(dot(x,x));
}
double angle(const Vec& a,const Vec& b)
//夹角,0~180°
{
return acos(dot(a,b)/len(a)/len(b));
}
double angle1(const Vec& a,const Vec& b)
//夹角,带方向,a到b逆时针为正,顺时针为负,共线为0
{
return acos(dot(a,b)/len(a)/len(b))*(dcmp(cross(a,b)));
}
Vec rotate(const Vec& a,const double& rad)
//旋转,正为逆时针,负为顺时针
{
return Vec(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
}
Vec normal(const Vec& x)
//单位法线,左转90°后除以自身长度
{
double l=len(x);
return Vec(-x.y/l,x.x/l);
}
Vec normal1(const Vec& x)
//法线,不归一化
{
return Vec(-x.y,x.x);
}
Point lineline(const Point& p,const Vec& v,const Point& q,const Vec& w)
//直线交点,GetLineIntersection
{
return p+v*cross(w,p-q)/cross(v,w);
}
double ptline(const Point& p,const Point& a,const Point& b)
//point_to_line,点到直线距离,DistanceToLine
{
Vec v1=b-a,v2=p-a;
return fabs(cross(v1,v2)/len(v1));
}
double ptseg(const Point& p,const Point& a,const Point& b)
//point_to_segment,点到线段距离,DistanceToSegment
{
if(a==b) return len(p-a);
//Vec v1=b-a,v2=a-p,v3=p-b;
Vec v1=b-a,v2=p-a,v3=p-b;
if(dcmp(dot(v1,v2))<) return len(v2);
else if(dcmp(dot(v1,v3))>) return len(v3);
else return fabs(cross(v1,v2)/len(v1));
}
double area2(const Point& a,const Point& b,const Point& c)
//叉积对应平行四边形的面积
{
return cross(b-a,c-a);
}
double thrarea(const Point& a,const Point& b,const Point& c)
//三角形面积,绝对值
{
return fabs(cross(b-a,c-a)/);
}
bool ifpar(const Vec& a,const Vec& b)
//ifParallel
//是否共线/平行
{
return dcmp(cross(a,b))==;
}
Point pointline(const Point& p,const Point& a,const Vec& v)
//点在直线上投影,GetLineProjection
{
return a+v*(dot(p-a,v)/dot(v,v));
}
bool ifsegseg(const Point& a1,const Point& a2,const Point& b1,const Point& b2)
//SegmentProperIntersection,线段相交判定,不包含端点,不允许共线。有交点时求交点直接用直线交点即可
//此处就是求两条线段的两个端点是否都分别在另一条线段的两侧
{
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)<;
}
bool ifonseg(const Point& p,const Point& a1,const Point& a2)
//OnSegment,点是否在线段上
//这样就能判定向量p a1与p a2共线,且方向相反
{
return dcmp(cross(a1-p,a2-p))==&&dcmp(dot(a1-p,a2-p))<;
}
bool ifsegseg1(const Point& a1,const Point& a2,const Point& b1,const 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)<)||
(dcmp(c1)==&&dcmp(c2)==)||ifonseg(a1,b1,b2)||
ifonseg(a2,b1,b2)||ifonseg(b1,a1,a2)||ifonseg(b2,a1,a2);
}
double polyarea(Point p[],int n)
//PolygonArea,有向面积,要求点按顺序能组成多边形(不会边相交,可以凹),如果顺时针转就是负,逆时针就是正(未验证)
{
double ans=;
for(int i=;i<n-;i++)
ans+=cross(p[i]-p[],p[i+]-p[]);
return ans/;
}
};
using namespace X;
Point p[];
Point p2[];
int n,v,e,T;
int main()
{
int i,j;
scanf("%d",&n);
while(n!=)
{
v=;e=n-;
scanf("%lf%lf",&p[].x,&p[].y);
p2[++v]=p[];
for(i=;i<=n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);p2[++v]=p[i];
for(j=;j<=i-;j++)
{
if(ifsegseg(p[i-],p[i],p[j],p[j+]))
p2[++v]=lineline(p[i-],p[i]-p[i-],p[j],p[j+]-p[j]);
}
}
sort(p2+,p2+v+);
v=unique(p2+,p2+v+)-p2-;
for(i=;i<n;i++)
for(j=;j<=v;j++)
if(ifonseg(p2[j],p[i],p[i+]))
e++;
printf("Case %d: There are %d pieces.\n",++T,e+-v);
scanf("%d",&n);
}
return ;
}

That Nice Euler Circuit UVALive - 3263 || 欧拉公式的更多相关文章

  1. POJ--2284--That Nice Euler Circuit【平面图欧拉公式】

    链接:id=2284">http://poj.org/problem?id=2284 题意:一个自己主动绘图的机器在纸上(无限大)绘图,笔尖从不离开纸,有n个指令,每一个指令是一个坐标 ...

  2. POJ 2284 That Nice Euler Circuit (LA 3263 HDU 1665)

    http://poj.org/problem?id=2284 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&a ...

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

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

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

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

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

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

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

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

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

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

  8. UVa 10735 (混合图的欧拉回路) Euler Circuit

    题意: 给出一个图,有的边是有向边,有的是无向边.试找出一条欧拉回路. 分析: 按照往常的思维,遇到混合图,我们一般会把无向边拆成两条方向相反的有向边. 但是在这里却行不通了,因为拆成两条有向边的话, ...

  9. UVA 10735 Euler Circuit 混合图的欧拉回路(最大流,fluery算法)

    题意:给一个图,图中有部分是向边,部分是无向边,要求判断是否存在欧拉回路,若存在,输出路径. 分析:欧拉回路的定义是,从某个点出发,每条边经过一次之后恰好回到出发点. 无向边同样只能走一次,只是不限制 ...

随机推荐

  1. 表皮囊肿?wtf

    https://baike.baidu.com/item/%E8%A1%A8%E7%9A%AE%E5%9B%8A%E8%82%BF/7852024?fr=aladdin

  2. ffm算法

    www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf  读书笔记 The effect of feature conjunctions(组合特征) is difficul ...

  3. 【c++】【转】结构体字节对齐

    http://www.cnblogs.com/heyonggang/archive/2012/12/11/2812304.html

  4. 【stl学习笔记】vector

    vector是定义于namespace std内的template: namespace std { template<class T, class Allocator = allocator& ...

  5. Android网络通信之Socket

    在移动APP开发中.网络通信数据传输是必定存在的.移动APP离开了网络通信数据传输的功能方式,就好比一潭死水,永远都 是原来的样子. 提到网络通信传输数据.首先出如今程序猿脑海中的是HTTP协议传输, ...

  6. 【转载】C# 装箱和拆箱[整理]

    1.      装箱和拆箱是一个抽象的概念 2.      装箱是将值类型转换为引用类型 :拆箱是将引用类型转换为值类型       利用装箱和拆箱功能,可通过允许值类型的任何值与Object 类型的 ...

  7. linux中用anaconda使用不同版本python

    1.使用命令conda create --name python36 python=3.6  #你想使用哪个版本就下载哪个版本,--name后面跟的是该虚拟环境的名称 2.需要使用python3.6时 ...

  8. 关于 iOS 的 StoryBoard,接受的那一刻才发现她的美 - 当然美的事物都须要业心照料

    关于 iOS 的 StoryBoard,接受的那一刻才发现她的美 - 当然美的事物都须要业心照料 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循&quo ...

  9. 动态追踪技术 Dynamic Tracing

    https://openresty.org/posts/dynamic-tracing/ 工欲性能调优,必先利其器(2)- 火焰图| PingCAP https://pingcap.com/blog- ...

  10. javascript base64 编码,兼容ie6789

    用Javascript进行base64编码,在高版本的IE浏览器(IE9以上版本),和firefox,chrome浏览器里是非常方便的.这些浏览器的window对象中内置了base64的编码和解码方法 ...