LA 3263 That Nice Euler Circuit(欧拉定理)
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 N
4, 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(欧拉定理)的更多相关文章
- 简单几何(求划分区域) LA 3263 That Nice Euler Circuit
题目传送门 题意:一笔画,问该图形将平面分成多少个区域 分析:训练指南P260,欧拉定理:平面图定点数V,边数E,面数F,则V + F - E = 2.那么找出新增的点和边就可以了.用到了判断线段相 ...
- UVALive - 3263 That Nice Euler Circuit (几何)
UVALive - 3263 That Nice Euler Circuit (几何) ACM 题目地址: UVALive - 3263 That Nice Euler Circuit 题意: 给 ...
- UVALi 3263 That Nice Euler Circuit(几何)
That Nice Euler Circuit [题目链接]That Nice Euler Circuit [题目类型]几何 &题解: 蓝书P260 要用欧拉定理:V+F=E+2 V是顶点数; ...
- 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. 其 ...
- uvalive 3263 That Nice Euler Circuit
题意:平面上有一个包含n个端点的一笔画,第n个端点总是和第一个端点重合,因此团史一条闭合曲线.组成一笔画的线段可以相交,但是不会部分重叠.求这些线段将平面分成多少部分(包括封闭区域和无限大区域). 分 ...
- hdu 1665 That Nice Euler Circuit(欧拉定理)
输入n个点,然后从第一个点开始,依次链接点i->点i+1,最后回到第一点(输入中的点n),求得到的图形将平面分成了多少部分. 根据欧拉定理 v_num + f_num - e_num = 2可知 ...
- UVALive 3263: That Nice Euler Circuit (计算几何)
题目链接 lrj训练指南 P260 //==================================================================== // 此题只需要考虑线 ...
- poj2284 That Nice Euler Circuit(欧拉公式)
题目链接:poj2284 That Nice Euler Circuit 欧拉公式:如果G是一个阶为n,边数为m且含有r个区域的连通平面图,则有恒等式:n-m+r=2. 欧拉公式的推广: 对于具有k( ...
- POJ2284 That Nice Euler Circuit (欧拉公式)(计算几何 线段相交问题)
That Nice Euler Circuit Time Limit: 3000MS M ...
随机推荐
- [CSP-S模拟测试]:小P的生成树(数学+Kruskal)
题目描述 小$P$是个勤于思考的好孩子,自从学习了最大生成树后,他就一直在想:能否将边权范围从实数推广到复数呢?可是马上小$P$就发现了问题,复数之间的大小关系并没有定义.于是对于任意两个复数$z_1 ...
- 北风设计模式课程---访问者(Visitor)模式
北风设计模式课程---访问者(Visitor)模式 一.总结 一句话总结: 设计模式是日常问题的经验总结方案,所以学好设计模式对日常出现的问题可以有很好的解决. 访问者设计模式有点神似 抽象工厂模式, ...
- docker-dnsmasq使用
docker-dnsmasq支持通过web页面配置域名映射,镜像地址:https://hub.docker.com/r/jpillora/dnsmasq 使用步骤如下: 1.在Docker宿主上创建 ...
- el-date-picker用法
需求:1.默认时间是当天开始到此刻的时间 2.快捷键为今天.昨天.最近一周.最近30天.最近90天 3.不可以清空,必选项
- commons-collections包中的常用的工具类
commons-collections包中的常用的工具类 <dependency> <groupId>commons-collections</groupId> & ...
- windows10下基于docker的bvlc/caffe环境搭建与使用
docker 安装参见docker官网,当cmd出现以下图像时安装正确; 然后进行bvlc/caffe环境创建,有两种,一种是直接pull github的bvlc,一种是本地创建image,直接使用g ...
- Vue引入Jquery和Bootstrap
一.引入jquery包 npm i jquery 二.配置jquery 在webpack.base.conf.js中加载juery插件 所以要配置该文件 三.引入Bootstrap npm i bo ...
- 红帽虚拟化RHEV-PXE批量安装RHEV-H
目录 目录 前言 软件环境 前提 部署 PXE 环境 使用 yum 安装所需软件 配置 DHCP 配置 TFTP-Server 配置 vsftpd 服务用于提供安装系统所需软件包 安装 kicksta ...
- QCOW2/RAW/qemu-img 概念浅析
目录 目录 扩展阅读 RAW QCOW2 QEMU-COW 2 QCOW2 Header QCOW2 的 COW 特性 QCOW2 的快照 qemu-img 的基本使用 RAW 与 QCOW2 的区别 ...
- python 设置开机启动脚本
1.创建python_auto.bat的快捷方式,放入启动项: C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\ ...