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 and 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 sample 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.
 #include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
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& a) const
{
if(a.x != x) return x < a.x;
return y < a.y;
}
};
typedef Point Vector;
const int maxn = ;
Point P[maxn], V[maxn*maxn]; int dcmp(double x)
{
if(fabs(x) < eps) return ;
else return x< ? -:;
}
bool operator == (const Point& a, const Point &b)
{
return dcmp(a.x-b.x) == && dcmp(a.y-b.y) == ;
}
Vector operator - (Point A, Point B)
{
return Vector(A.x - B.x, A.y-B.y);
}
Vector operator + (Point A, Point B)
{
return Vector(A.x +B.x, A.y+B.y);
}
Vector operator * (Point A,double P)
{
return Vector(A.x *P , A.y*P);
}
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 SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2)
{
double c1 = Cross(a2-a1,b1-a1),c2 = Cross(a2-a1,b2-b1);
double c3 = Cross(b2-b1,a1-b1),c4 = Cross(b2-b1,a2-b1);
return dcmp(c1)*dcmp(c2)< && dcmp(c3)*dcmp(c4)<;
}
bool OnSegment(Point p,Point a1,Point a2)
{
return dcmp(Cross(a1-p,a2-p))== && dcmp(Dot(a1-p,a2-p))<;
}
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 main()
{
//freopen("a.txt","r",stdin);
int n,kase =;
while(scanf("%d",&n) &&n)
{
for(int i=; i<n; i++)
{
scanf("%lf %lf",&P[i].x,&P[i].y);
V[i]=P[i];
}
n--;
int c=n,e=n;
for(int i=; i<n; i++)
for(int j=i+; j<n; j++)
if(SegmentProperIntersection(P[i],P[i+],P[j],P[j+]))
V[c++] = GetLineIntersection(P[i],P[i+]-P[i],P[j],P[j+]-P[j]); sort(V,V+c);
c=unique(V,V+c) -V;
for(int i=; i<c; i++)
for(int j=; j<n; j++)
if(OnSegment(V[i],P[j],P[j+])) e++;
printf("Case %d: There are %d pieces.\n",++kase,e+-c);
} return ;
}

平面分成区域数

Uva 1342 - That Nice Euler Circuit的更多相关文章

  1. UVA LIVE-3263 - That Nice Euler Circuit

    画一个顶点为偶数的封闭的二维图,当然.这个图能够自交,给出画的过程中的一些轨迹点.求出这个图把二次元分成了几部分,比如三角形把二次元分成了两部分. 这个的话,有图中顶点数+部分数-棱数=2的定律,这是 ...

  2. UVa 10735 - Euler Circuit(最大流 + 欧拉回路)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

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

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

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

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

  5. Euler Circuit UVA - 10735(混合图输出路径)

    就是求混合图是否存在欧拉回路 如果存在则输出一组路径 (我就说嘛 咱的代码怎么可能错.....最后的输出格式竟然w了一天 我都没发现) 解析: 对于无向边定向建边放到网络流图中add(u, v, 1) ...

  6. UVA 10735 Euler Circuit (最大流)

    题意:求混合图的欧拉路径. 一句话总结:网络流,最主要在于建图,此题是将出度则是和流量联系在了一起,用最大流来调整边的指向. 分析: 这题的困难之处在于无向边只能用一次,相当于一个方向未定的有向边. ...

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

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

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

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

  9. UVA-10735 - Euler Circuit(混合欧拉回路输出)

    题意:给你一个图,有N个点,M条边,这M条边有的是单向的,有的是双向的. 问你能否找出一条欧拉回路,使得每条边都只经过一次! 分析: 下面转自别人的题解: 把该图的无向边随便定向,然后计算每个点的入度 ...

随机推荐

  1. java_final

  2. 一起talk C栗子吧(第二十回:C语言实例--括号匹配)

    各位看官们,大家好.前几回中咱们说了堆栈的原理,而且举了实际的样例进行讲解,这一回咱们说的例 子是:括号匹配. 括号匹配使用了堆栈的原理,大家能够从样例看出来.所以我们把它们放在一起.闲话 休提.言归 ...

  3. Ubuntu 14.04根据系统,休眠后不能启动要解决的问题

    简介: 提升Ubuntu制度14.04之后,当系统进入休眠,我们不能再次启动,直接崩溃,凡出了问题? 1.   问题纳入 Ubuntu升级系统14.04之后.通过系统的Power设置休眠时间,在系统进 ...

  4. 最流行的android组件大全

    目录 [−] 工具和教程 UI组件 类库 游戏引擎 Android HTML5应用 Android 是目前最流行的移动操作系统(还需要加之一吗?). 随着新版本的不断发布, Android的功能也日益 ...

  5. 支持多QQ登录的软件

    支持多QQ登录,批量加好友,批量回复QQ消息,当然也能接收 下载链接:多QQ登录软件

  6. Hacker(23)----破解常见文件密码

    Win7中,office文档.压缩文件等都是常见的文件,这些文档含有重要的信息,即使用户为这些文件设置了密码,黑客也会有办法破解. 一.破解office文档密码 破解office文档密码常用工具是Ad ...

  7. oracle 双机热备,oracle dataguard 和oracle rac的区别和联系(转)

    Data Guard 是Oracle的远程复制技术,它有物理和逻辑之分,但是总的来说,它需要在异地有一套独立的系统,这是两套硬件配置可以不同的系统,但是这两套系统的软件结构保持一致,包括软件的版本,目 ...

  8. asp.net操作xml(增删查改)

    asp.net操作xml 1.xml文档Products.xml <?xml version="1.0" encoding="utf-8"?> &l ...

  9. C# 将窗口移动到指定位置

    private void button1_Click(object sender, EventArgs e) { Frm f = new Frm(); f.StartPosition = FormSt ...

  10. JS高级程序设计学习笔记之数组

    数组创建的方式 var str = new Array();放入数字即为设置数组长度 var str = []; 数组的length可读可写 监测数组 Array.isArray()方法确定某个值是不 ...