描述


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. C# 自定义排序

    /// <summary> /// 实体 /// </summary> public class Product { public int ID { get; set; } p ...

  2. C++ socket开发1

    服务端 setlocale(LC_ALL,"Chinese-simplified"); WORD wVersionRequested; WSADATA wsaData; int e ...

  3. iOS开发——免证书调试(Xcode7,iOS9)

    (资料已做好,待整理成文章……)

  4. Excel对话框大全

    Excel对话框大全 序号 名称 描述 1 Application.Dialogs(1).Show 是调用打开对话框  2 Application.Dialogs(5或145).Show 是调用另存为 ...

  5. java新手笔记22 接口示例2

    1.USB package com.yfs.javase; public interface USB { //定义规范 public void read(); public void write(); ...

  6. 在.NET 应用程序设计中如何选择Class, Abstract Class and Interface

    关键字: Type– 类型 Class - 类 Abstract - 抽象的 Interface - 接口 Member - 成员 Method - 方法 Property - 属性 预备知识:在阅读 ...

  7. 基于IAccessible接口的QQ窗口信息获取的实现

    这个技术现在已经封装成DLL免费开放给大家使用了,详情请加群221487171 可以访问官方网站下载 http://www.guihelper.com/ 主要技术(Microsoft Active A ...

  8. PHP-traits新特性详解

    自 PHP 5.4.0 起,PHP 实现了代码复用的一个方法,称为 traits. Traits 是一种为类似 PHP 的单继承语言而准备的代码复用机制.Trait 为了减少单继承语言的限制,使开发人 ...

  9. 新浪微博登录接口(PHP版)

    CI框架下 新浪微博登录接口完整版说明:本贴只适合CI框架.功能实现:登录接口跳转链接成功,获取用户信息(包括最重要的u_id)成功,将用户与本地平台连接起来,用户登录成功后信息的存储,本地数据库第三 ...

  10. 使用Yii框架中遇到的三个问题

    以下由我们在信易网络公司开发项目的时候终结出的一些经验 使用Yii框架中遇到的三个问题 1.main.php文件中欲引入全局变量的问题 还原一下此问题:在Yii框架中,main.php一般会作为整个应 ...