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. bzoj1151

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1151 状压DP,枚举前面4个,使得环型变线型. #include<cstdio> ...

  2. 【绿茶书情】:《SOHO小报》和《凤… - 绿茶的日志 - 网易博客

    [绿茶书情]:<SOHO小报>和<凤- - 绿茶的日志 - 网易博客 [绿茶书情]:<SOHO小报>和<凤-  

  3. 关于maven-jetty-plugin 自动重启问题

    <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin ...

  4. python3-day6(模块)

    一.OS模块 1.os.system('ls -l') #子shell运行,获取返回值,不是结果. 2.os.popen('ls -l').read() #获取结果. 二.sys模块 1.sys.ar ...

  5. 有关JAVA基础学习中的集合讨论

        很高兴能在这里认识大家,我也是刚刚接触后端开发的学习者,相信很多朋友在学习中都会遇到很多头疼的问题,希望我们都能够把问题分享出来,把自己的学习思路整理出来,我们一起探讨一起成长.    今天我 ...

  6. Pojo和JavaBean的区别(转载)

    OJO(Plain Old Java Object)这个名字用来强调它是一个普通java对象,而不是一个特殊的对象. 2005年11月时,“POJO”主要用来指代那些没用遵从特定的Java对象模型,约 ...

  7. Zedboard甲诊opencv图像处理(二)

    通过前面的努力已经得到了n个轮廓了,现在要把最终的轮廓确定下来 ,然后进行特征提取. 先深入分析下轮廓和处理轮廓的方法:http://blog.csdn.net/hitwengqi/article/d ...

  8. Android 编程下模拟 HOME 键效果

    Android 应用开发中,有一种场景,就是我们不希望用户按 Back 键直接退出 Activity,而是希望应用隐藏到后台,类似于按 Home 键的效果.参考如下代码即可实现这样的效果: publi ...

  9. Java性能漫谈-数组复制之System.arraycopy

    当我还年幼的时候,我很任性,复制数组也是,写一个for循环,来回倒腾,后来长大了,就发现了System.arraycopy的好处. 为了测试俩者的区别我写了一个简单赋值int[100000]的程序来对 ...

  10. 在Fedora20上安装Oracle 12c

    本文将引导大家在Fedora20的环境下成功安装Oracle12c. 安装前的准备 编辑/etc/hosts文件,添加本机名称 编辑/etc/selinux/config文件 编辑/etc/redha ...