描述


https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1264

给出一个一笔画的所有折点,求这个一笔画共把平面分成了几个区域(包括优先区域与无限区域).

3263 - That Nice Euler Circuit

3263
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, Y 0) which moves the
pencil to some starting position (X0, Y 0). 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, Y 0). 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
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
0ACM-ICPC Live Archive: 3263 – That Nice Euler Circuit
Sample Output
Case 1: There are 2 pieces.
Case 2: There are 5 pieces.
2/2

分析


欧拉定理:平面图的顶点数V,边数E,面数F满足V+F-E=2.

这样一来,只要求点数和边数即可.

点分为两部分:1.本来就有的.2.相交(规范相交)得到的.

边也可以分为两部分:1.本来就有的.2.每因为规范相交而产生一个新的点,边的个数+1.

注意:

1.有可能三线共点,此时交点被算了两次,所以要去重,可以用unique函数(数组必须有序,如果从a[1]开始,则返回值要-(a+1)).

2.输入是n+1个点!他在最后把起点又输入了一遍!查了这么久...

 #include <bits/stdc++.h>
using namespace std; const int maxn=+;
const double eps=1e-; int n,kase;
struct Point{
double x,y;
Point(double x=,double y=):x(x),y(y){}
}p[maxn],v[maxn*maxn];
typedef Point Vector;
int dcmp(double x){
if(fabs(x)<eps) return ;
return x<?-:;
}
Vector operator + (Vector a,Vector b){ return Vector(a.x+b.x,a.y+b.y); }
Vector operator - (Vector a,Vector b){ return Vector(a.x-b.x,a.y-b.y); }
Vector operator * (Vector a,double p){ return Vector(a.x*p,a.y*p); }
Vector operator / (Vector a,double p){ return Vector(a.x/p,a.y/p); }
bool operator < (const Point &a,const Point &b){ return a.x<b.x||(a.x==b.x&&a.y<b.y); }
bool operator == (const Point &a,const Point &b){ return dcmp(a.x-b.x)==&&dcmp(a.y-b.y)==; }
double dot(Vector a,Vector b){ return a.x*b.x+a.y*b.y; }
double cross(Vector a,Vector b){ return a.x*b.y-a.y*b.x; }
bool segment_proper_intersection(Point a,Point b,Point c,Point d){
double c1=cross(b-a,c-a), c2=cross(b-a,d-a),
c3=cross(d-c,a-c), c4=cross(d-c,b-c);
return (dcmp(c1)^dcmp(c2))==-&&(dcmp(c3)^dcmp(c4))==-;
}
Point get_line_intersection(Point P,Vector v,Point Q,Vector w){
Vector u=P-Q;
double t=cross(w,u)/cross(v,w);
return P+v*t;
}
bool on_segment(Point p,Point a,Point b){ return dcmp(cross(a-p,b-p))==&&dcmp(dot(a-p,b-p)<); } void solve(){
for(int i=;i<=n;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
v[i]=p[i];
}
n--;//输入的是n+1个点
int c=n,e=n;
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++){
if(segment_proper_intersection(p[i],p[i+],p[j],p[j+]))
v[++c]=get_line_intersection(p[i],p[i+]-p[i],p[j],p[j+]-p[j]);}
sort(v+,v+c+);
c=unique(v+,v+c+)-(v+);//去重,注意减去的时(v+1)
for(int i=;i<=c;i++)
for(int j=;j<=n;j++)
if(on_segment(v[i],p[j],p[j+])) e++;
printf("Case %d: There are %d pieces.\n",++kase,e+-c);//欧拉定理
}
int main(){
while(scanf("%d",&n)&&n) solve();
return ;
}

LA_3263_That_Nice_Euler_Circuits_(欧拉定理+计算几何基础)的更多相关文章

  1. nyis oj 68 三点顺序 (计算几何基础)

    三点顺序 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描写叙述 如今给你不共线的三个点A,B,C的坐标,它们一定能组成一个三角形,如今让你推断A,B,C是顺时针给出的还是逆 ...

  2. 【BZOJ】1043: [HAOI2008]下落的圆盘(计算几何基础+贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1043 唯一让我不会的就是怎么求圆的周长并QAAQ... 然后发现好神!我们可以将圆弧变成$[0, 2 ...

  3. 计算几何基础——矢量和叉积 && 叉积、线段相交判断、凸包(转载)

    转载自 http://blog.csdn.net/william001zs/article/details/6213485 矢量 如果一条线段的端点是有次序之分的话,那么这种线段就称为 有向线段,如果 ...

  4. BZOJ_1610_[Usaco2008_Feb]_Line连线游戏_(计算几何基础+暴力)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1610 给出n个点,问两两确定的直线中,斜率不同的共有多少条. 分析 暴力枚举直线,算出来斜率放 ...

  5. 二维计算几何基础题目泛做(SYX第一轮)

    题目1: POJ 2318 TOYS 题目大意: 给一个有n个挡板的盒子,从左到右空格编号为0...n.有好多玩具,问每个玩具在哪个空格里面. 算法讨论: 直接叉积判断就可以.注意在盒子的边界上面也算 ...

  6. 计算几何基础算法几何C++实现

    This file is implementation of Common Common Computational Geometry Algorithms.Please please pay att ...

  7. 【POJ】1556 The Doors(计算几何基础+spfa)

    http://poj.org/problem?id=1556 首先路径的每条线段一定是端点之间的连线.证明?这是个坑...反正我是随便画了一下图然后就写了.. 然后re是什么节奏?我记得我开够了啊.. ...

  8. 【POJ】2318 TOYS(计算几何基础+暴力)

    http://poj.org/problem?id=2318 第一次完全是$O(n^2)$的暴力为什么被卡了-QAQ(一定是常数太大了...) 后来排序了下点然后单调搞了搞..(然而还是可以随便造出让 ...

  9. 【POJ】2653 Pick-up sticks(计算几何基础+暴力)

    http://poj.org/problem?id=2653 我很好奇为什么这样$O(n^2)$的暴力能过.... 虽然说这是加了链表优化的,但是最坏不也是$O(n^2)$吗...(只能说数据太弱.. ...

随机推荐

  1. Find Minimum in Rotated Sorted Array问题的困惑

    今天做了两题,第二题没解出来,发现太麻烦了,放弃了……明天脑子清楚的时候再做. 第一题就是标题中的这个问题.在一个旋转排序数组中找出最小的值. 针对该问题出了两道不同要求的题目,分别是不考虑重复元素的 ...

  2. iOS 9 Spotlight搜索 OC版

    介绍:    在WWDC 2015会议上,苹果官方公布了iOS9.除开许多新的特性和增强功能,这次升级也给了开发者们一个机会让他们的app里的内容能通过Spotlight 搜索功能被发现和使用.在iO ...

  3. VB,VBS,VBA,ASP可引用的库参考

    文件系统对象相关: ("SCRIPTING.FILESYSTEMOBJECT") 字典相关: ("SCRIPTING.DICTIONARY") 脚本外壳相关:  ...

  4. 九度OJ 1042 Coincidence -- 动态规划(最长公共子序列)

    题目地址:http://ac.jobdu.com/problem.php?pid=1042 题目描述: Find a longest common subsequence of two strings ...

  5. ECMA5.1中Object.seal()和Object.freeze()的区别

    1  Object.seal(O)的调用 When the seal function is called, the following steps are taken:   If Type(O) i ...

  6. CentOS 5.4 制作 Python 2.6 RPM 包的方法

    不知道什么原因,CentOS 5.4 了,默认的Python的版本还是2.4的. 但是Python在CentOS里面的又非常的重要,可是 2.4版本的Python有很多的模块没有,最新的Python ...

  7. SQLServer:定时作业

    SQLServer:定时作业: 如果在SQL Server 里需要定时或者每隔一段时间执行某个存储过程或3200字符以内的SQL语句时,可以用管理-SQL Server代理-作业来实现 也快可以定时备 ...

  8. JS将搜索的关键字高亮显示实现代码

    这篇文章介绍了JS将搜索的关键字高亮显示实现代码,有需要的朋友可以参考一下 用JS让文章内容指定的关键字加亮 是这样的.. 现在有这些关键字:美容,生活,购物 当在文章里头出现这些关键字,就把它加亮显 ...

  9. JFreeChart入学教程

    JFreeChart入学教程 2011-08-08 14:55:19|  分类: 技术篇 |举报 |字号 订阅   JFreeChart 是一组功能强大.灵活易用的Java绘图API,使用它可以生成多 ...

  10. 学习python网络数据采集笔记-1、2章

    英文不好只能看中文版的.邮电出版社翻译的真很烂. 以上是吐槽,以下是正文. 书中用的pthon 3.X版本,建议安装python3.4以上的版本,低版本的没有自带pip安装插件会比较麻烦. 下载地址: ...