That Nice Euler Circuit

Little Joey invented a scrabble

machine that he called Euler, after the great mathematician. In his primary school Joey heard about the nice story of how Euler started the study about graphs. The problem in that story was - let me remind you - to draw a graph on a paper without lifting your pen, and finally return to the original position. Euler proved that you could do this if and only if the (planar) graph you created has the following two properties: (1) The graph is connected; and (2) Every vertex in the graph has even degree.

Joey's Euler machine works exactly like this. The device consists of a pencil touching the paper, and a control center issuing a sequence of instructions. The paper can be viewed as the infinite two-

dimensional plane; that means you do not need to worry about if the pencil will ever go off the boundary.

In the beginning, the Euler machine will issue an instruction of the form (X0, Y0) which moves the pencil to some starting position (X0, Y0). Each subsequent instruction is also of the form (X'Y'), which means to move the pencil from the previous position to the new position (X'Y'), thus draw a line segment on the paper. You can be sure that the new position is different from the previous position for each instruction. At last, the Euler machine will always issue an instruction that move the pencil back to the starting position(X0, Y0). In addition, the Euler machine will definitely not draw any lines that overlay other lines already drawn. However, the lines may intersect.

After all the instructions are issued, there will be a nice picture on Joey's paper. You see, since the pencil is never lifted from the paper, the picture can be viewed as an Euler circuit.

Your job is to count how many pieces (connected areas) are created on the paper by those lines drawn by Euler.

Input

There are no more than 25 test cases. Ease case starts with a line containing an integer N4, which is the number of instructions in the test case. The following N pairs of integers give the instructions a

nd appear on a single line separated by single spaces. The first pair is the first instruction that gives the coordinates of the starting position. You may assume there are no more than 300 instructions in each test case, and all the integer coordinates are in the range (-300, 300). The input is terminated when N is 0.

Output

For each test case there will be one output line in the format

Case x: There are w pieces.,

where x is the serial number starting from 1.

Note: The figures below illustrate the two sa

mple input cases.

Sample Input

5
0 0 0 1 1 1 1 0 0 0
7
1 1 1 5 2 1 2 5 5 1 3 5 1 1
0

Sample Output

Case 1: There are 2 pieces.
Case 2: There are 5 pieces.
 本题想到了还是不难!!

 首先显然要用欧拉定理  V+F-E=;从而F=E+-C;

 点个数=原来的+新增的;(可能三条线段交于一点,故新增的点要去重)

 然后在每一条线段上若新增一个点边就+!!!

 #include<stdio.h>
#include<math.h>
#include<algorithm>
#include<set>
using namespace std;
#define eps 1e-8
#define oo 100000000
#define pi acos(-1)
struct point
{
double x,y;
point(double _x = 0.0,double _y = 0.0)
{
x =_x;
y =_y;
}
point operator -(const point &b)const
{
return point(x - b.x, y - b.y);
}
point operator +(const point &b)const
{
return point(x +b.x, y + b.y);
}
double operator ^(const point &b)const
{
return x*b.y - y*b.x;
}
double operator *(const point &b)const
{
return x*b.x + y*b.y;
}
void input()
{
scanf("%lf%lf",&x,&y);
}
}; int dcmp(double a)//判断一个double型的符号
{
if(fabs(a)<eps)return ;
if(a>)return ;
else return -;
} point operator |(point a,double p)//重载数乘,向量*数!!!
{
return point(a.x*p,a.y*p);
} bool operator ==(const point &a,const point &b)
{
return dcmp(a.x-b.x)==&&dcmp(a.y-b.y)==;
} bool SegmentGuiFanXiangJiao(point a1,point a2,point b1,point b2)
{
double c1=(a2-a1)^(b1-a1),c2=(a2-a1)^(b2-a1),
c3=(b2-b1)^(a1-b1),c4=(b2-b1)^(a2-b1);
return dcmp(c1)*dcmp(c2)<&&dcmp(c3)*dcmp(c4)<;
} point getjiaodian(point p,point v,point q,point w)//前提有唯一交点!!参数方程,v,w都为方向向量,p,q,为两直线上的点,求交点 !
{
point u;
u=p-q;
double t=(w^u)/(v^w);
v.x=t*v.x;v.y=t*v.y;
return p+v;
} bool cmp(point a,point b)
{
if(dcmp(a.x-b.x)==)return a.y<b.y;
return a.x<b.x;
}
bool OnSegment(point p,point a1,point a2)//不规范相交,点在另一条线段上
{
return dcmp((a1-p)^(a2-p))==&&dcmp((a1-p)*(a2-p))<;
} point p[],V[];
int main()
{
int i,j,n,ca;
ca=;
while(~scanf("%d",&n)&&n)
{
ca++;
int c=;
for(i=;i<n;i++)p[i].input(),V[c++]=p[i];
n--;
int e=n;
for(i=;i<n;i++)
for(j=i+;j<n;j++)
if(SegmentGuiFanXiangJiao(p[i],p[i+],p[j],p[j+]))
V[c++]=getjiaodian(p[i],p[i+]-p[i],p[j],p[j+]-p[j]);
sort(V,V+c,cmp);//cmp必须要有,否则编译就bug啦!!
c=unique(V,V+c)-V;
for(i=;i<c;i++)
for(j=;j<n;j++)
if(OnSegment(V[i],p[j],p[j+]))e++;
printf("Case %d: There are %d pieces.\n",ca,e+-c);
}
return ;
}

LA 3263 That Nice Euler Circuit(欧拉定理)的更多相关文章

  1. 简单几何(求划分区域) LA 3263 That Nice Euler Circuit

    题目传送门 题意:一笔画,问该图形将平面分成多少个区域 分析:训练指南P260,欧拉定理:平面图定点数V,边数E,面数F,则V + F - E =  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(欧拉定理)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21363 [思路] 欧拉定理:V+F-E=2.则F=E-V+2. 其 ...

  5. uvalive 3263 That Nice Euler Circuit

    题意:平面上有一个包含n个端点的一笔画,第n个端点总是和第一个端点重合,因此团史一条闭合曲线.组成一笔画的线段可以相交,但是不会部分重叠.求这些线段将平面分成多少部分(包括封闭区域和无限大区域). 分 ...

  6. hdu 1665 That Nice Euler Circuit(欧拉定理)

    输入n个点,然后从第一个点开始,依次链接点i->点i+1,最后回到第一点(输入中的点n),求得到的图形将平面分成了多少部分. 根据欧拉定理 v_num + f_num - e_num = 2可知 ...

  7. UVALive 3263: That Nice Euler Circuit (计算几何)

    题目链接 lrj训练指南 P260 //==================================================================== // 此题只需要考虑线 ...

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

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

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

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

随机推荐

  1. git pull失误提交

    git pull 提示错误,Your local changes to the following files would be overwritten by merge 到公司后本来打算git pu ...

  2. vue中动态加载图片路径的方法

    assets:在项目编译的过程中会被webpack处理解析为模块依赖,只支持相对路径的形式,如< img src=”./logo.png”>和background:url(./logo.p ...

  3. oracle 表连接 - sort merge joins 排序合并连接

    https://blog.csdn.net/dataminer_2007/article/details/41907581一. sort merge joins连接(排序合并连接) 原理 指的是两个表 ...

  4. mysqlbinlog读懂binlog

    binlog 报unknown variable 'default-character-set=utf8' 方法1: 在/etc/my.cnf 中将default-character-set=utf8 ...

  5. linux中表示系统信息如cpu mem disk等内容都在 /proc

    linux中表示系统信息的 内容都在 /proc 要查看系统的任何信息, 如cpu mem 磁盘等等, 都在 /proc下, 如: cpuinfo ,meminfo diskstatus 等等

  6. Delphi XE2 之 FireMonkey 入门(21) - 和 FMX 相关的类(表)

    TObject TPersistent TComponent IInterface,IInterfaceComponentReference         TBasicAction TControl ...

  7. python常用包官网

    Pandas http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.reset_index.html?high ...

  8. 关于Tomcat的浅谈

    (今天看到tomcat已经更新到了9.0.24,这是一篇很早之前的文章,由于账号不想用了,所以搬到这里来,另外的账号要注销了) 1.Tomcat的下载 tomcat官网:http://tomcat.a ...

  9. 简单DP入门(一) 数字三角形

    数字三角形

  10. SSM001/构建maven多模块项目

    一.Idea构建maven多模块项目 1.创建maven项目--创建父模块 [1].File->New->Module... [2].点击next,填写:GroupId,ArtifactI ...