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. 瑞柏匡丞谈中国移动app的国际进阶路

    当今3.0互联时代,已然形成了一个移动化,互动化,全球化的完整体系.瑞柏匡丞也在常年与国内外客户的交流沟通中有了自己的些许见解. 国内的移动产业的发展已然非常迅速,但也正是因为各类企业的不断崛起,能够 ...

  2. 自定义checkbox样式

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. Android开发常用工具汇总

    Android开发常用工具汇总,本文章不断更新完善 一.数据库小工具Sqlite Developer  SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统,它的设计目标是嵌入式的, ...

  4. webService返回自定义类型的数据处理

    1.自定义一个Student 数据类型: package com.chnic.webservice; import java.io.Serializable; public class Student ...

  5. Hadoop动态加入/删除节点(datanode和tacktracker)

    大体,正确的做法是首选的配置文件,然后开始详细机对应的进程/停止操作. 网上一些资料说在调整配置文件的时候,优先使用主机名而不是IP进行配置. 总的来说加入/删除DataNode和TaskTracke ...

  6. Action Result

    操作返回的内容成为操作结果 大多数情况下返回ViewResult,基类ActionResult 6钟标准类型: ViewResult:视图结果,包含HTML标记等元素 EmptyResult:空结果 ...

  7. 关于Ajax的技术组成与核心原理

    1.Ajax 特点: 局部刷新.提高用户的体验度,数据从服务器商加载 2.AJax的技术组成 不是新技术,而是之前技术的整合 Ajax: Asynchronous Javascript And Xml ...

  8. Java中的try/catch/finally

    样例1: public class Test{ public static String output = ""; public static void foo(int i){ t ...

  9. 【5】说说Laravel5的blade模板

    首先看一下以前的程序 routes.php PagesController.php resources/views/pages/about.blade.php 现在我们来简单的使用一下blade模板的 ...

  10. 初学 Play Framework 以及可能遇到的问题

    这段话之后都是我从别人那拷贝过来的资料,方便大家查阅 红色标注字体是我自己遇到的一些问题: 如果你遇到了这样的问题  :