描述


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. 实现输出h264直播流的rtmp服务器 flash直播服务器

    http://www.cnblogs.com/haibindev/archive/2012/04/16/2450989.html 实现输出h264直播流的rtmp服务器 RTMP(Real Time ...

  2. apache2.2 + tomcat6 整合以及集群配置整理

    运行环境:apache2.2.X + tomcat6.0.X + window xp 1. 安装Apache,服务启动后在浏览器中输入http://localhost进行测试,如果能看到一个" ...

  3. Xcode 7 支持http请求info.plist设置

    由于iOS9改用更安全的https,为了能够在iOS9中正常使用http发送网络请求,请在"Info.plist"中进行如下配置,否则影响SDK的使用. 1.找到项目中的 Info ...

  4. jquery动态添加/删除 tr/td

    <head runat="server"> <title></title> <!--easyui --> <link rel= ...

  5. 常用JS正则表达式收集

    1.去掉字符串前后空格,不会修改原有字符串,返回新串.str.replace(/(^\s*)|(\s*$)/g,'');

  6. 09.25日记(2014年9月25日23:22:06)用java这么多年面向对象我真的懂了吗,测试先行理念会玩吗

    二胡 (1)应该找些书来看看,工作N年并不代表就有N年的工作经验. (2)DiaTransit02,DiaDept02,DiaAirport02,DiaHighway02.都具有x,y属性为何不设计一 ...

  7. (poj) 1751 Highways

    Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has a very poor ...

  8. 下载APP 2个二维码合并到一个二维码

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  9. 关于APlayer播放器在打包安装后提示“没有注册类”的解决办法

    1.首先需要确定必要的DLL文件都已经在正确的安装目录下了: 2.项目中引用的DLL必须是Debug目录下的: 3.若后续修改或者重新注册了APlayer组件,那么所有的DLL都需要替换成最新的. 关 ...

  10. 设置Android程序的默认安装位置

    修改 AndroidManifest.xml 文件: <manifest xmlns:android="http://schemas.android.com/apk/res/andro ...