uvalive 3263 That Nice Euler Circuit
题意:平面上有一个包含n个端点的一笔画,第n个端点总是和第一个端点重合,因此团史一条闭合曲线。组成一笔画的线段可以相交,但是不会部分重叠。求这些线段将平面分成多少部分(包括封闭区域和无限大区域)。
分析:若是直接找出所有区域,或非常麻烦,而且容易出错。但用欧拉定理可以将问题进行转化,使解法变容易。
欧拉定理:设平面图的顶点数、边数和面数分别为V,E,F,则V+F-E=2。
这样,只需求出顶点数V和边数E,就可以求出F=E+2-V。
设平面图的结点由两部分组成,即原来的结点和新增的结点。由于可能出现三线共点,需要删除重复的点。
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<memory.h>
#include<cstdlib>
#include<vector>
#define clc(a,b) memset(a,b,sizeof(a))
#define LL long long int
using namespace std;
const int inf=0x3f3f3f3f;
const double eps = 1e-;
const int N = + ; struct Point
{
double x, y;
Point(double x = , double y = ) : x(x), y(y) { }
}; typedef Point Vector; Vector operator + (Vector A, Vector 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 * (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);
} 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) == ;
} 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;
} 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;
} bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2)
{
double c1 = Cross(a2-a1, b1-a1), c2 = Cross(a2-a1, b2-a1),
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 P[N], V[N*N]; int main()
{
int n, cas = ;
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 vcnt = n, ecnt = 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[vcnt++] = GetLineIntersection(P[i], P[i+]-P[i], P[j], P[j+]-P[j]);
}
sort(V, V+vcnt);
vcnt = unique(V, V+vcnt) - V;//去掉相邻元素中重复的,使用前先排序
for(int i = ; i < vcnt; i++)
for(int j = ; j < n; j++)
if(OnSegment(V[i], P[j], P[j+]))
ecnt++;
int ans = ecnt + - vcnt;
printf("Case %d: There are %d pieces.\n", ++cas, ans);
}
return ;
}
uvalive 3263 That Nice Euler Circuit的更多相关文章
- UVALive - 3263 That Nice Euler Circuit (几何)
UVALive - 3263 That Nice Euler Circuit (几何) ACM 题目地址: UVALive - 3263 That Nice Euler Circuit 题意: 给 ...
- 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 (计算几何)
题目链接 lrj训练指南 P260 //==================================================================== // 此题只需要考虑线 ...
- UVALi 3263 That Nice Euler Circuit(几何)
That Nice Euler Circuit [题目链接]That Nice Euler Circuit [题目类型]几何 &题解: 蓝书P260 要用欧拉定理:V+F=E+2 V是顶点数; ...
- LA 3263 That Nice Euler Circuit(欧拉定理)
That Nice Euler Circuit Little Joey invented a scrabble machine that he called Euler, after the grea ...
- 简单几何(求划分区域) LA 3263 That Nice Euler Circuit
题目传送门 题意:一笔画,问该图形将平面分成多少个区域 分析:训练指南P260,欧拉定理:平面图定点数V,边数E,面数F,则V + F - E = 2.那么找出新增的点和边就可以了.用到了判断线段相 ...
- 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 ...
- UVa 10735 (混合图的欧拉回路) Euler Circuit
题意: 给出一个图,有的边是有向边,有的是无向边.试找出一条欧拉回路. 分析: 按照往常的思维,遇到混合图,我们一般会把无向边拆成两条方向相反的有向边. 但是在这里却行不通了,因为拆成两条有向边的话, ...
随机推荐
- Partition an array around an interger
Partition an array of integers around a value such taht all elements less than x come before element ...
- WPF MultiDataTrigger
huhu <Style x:Key="Cell" TargetType="{x:Type Button}"> <Setter Property ...
- zoj 3365
题意 给你一个序列 改变尽可能少的数使其成为公差为一 递增的等差数列 可以将给你的序列减去一个等差数列 即num[i] -= i,若得到的数全部相等, 则说明给你的序列本身就满足条件 则只要寻求n ...
- 1987-A. 集训队选拔
描述 南邮ACM暑期集训队一年一度的选拔如火如荼的开始了.按照以往的惯例,通过ACM校赛预赛和决赛的两轮选拔,成绩优异者将入选集训队,获得下半年在各大赛区现场赛上与各路神牛角逐奖牌的机会.但是,校赛的 ...
- [Ruby on Rails系列]1、开发环境准备:Vmware和Linux的安装
Ruby on Rails是一个采用Ruby语言的遵循MVC模式的Web开发框架.使用RoR会得到更加快速爽快的Web开发体验.相比于Java EE,该框架使Web开发的速度和效率变得更加轻快和敏捷. ...
- ANDROID_MARS学习笔记_S01_003layout初步
一.layout介绍 二.测试linear_layout1.activity_main.xml <?xml version="1.0" encoding="utf- ...
- Firefox Security Toolkit 安装
目的: 下载Firefox Security Toolkit加载到浏览器里,增强渗透测试的工具利用. 兼容性: 目前仅支持Linux/Unix环境(可在kali上安装使用). 下载安装: wget h ...
- windows命令行编码与nodejs编码格式冲突的解决方式
今天写一个工具,由于大部分人使用的机器都是windows,在和nodejs结合的时候出问题了. win命令行的编码格式是gbk,而nodejs支持的编码只有:utf8 ascii和base64,必须让 ...
- java截取url中的值
Map<String, Object> urlSplit(String data){ StringBuffer strbuf = new StringBuffer(); StringBuf ...
- WIN7 XP设置MTU,提升下载速度
可能很少有雷友注意过“本机.网络”的“MTU”值对自己网络性能产生的影响.对于追求更快的下载速度来说,MTU值设置不当,就仿佛穿着高跟鞋跑步一般. MTU是什么? “MTU=最大传输单元 单位:字节” ...