pku 2284 That Nice Euler Circuit
题意:
给你n个点第n个点保证与第0个点相交,然后求这n个点组成的图形可以把整个平面分成几个面
思路:
这里的解题关键是知道关于多面体的欧拉定理
多面体:
设v为顶点数,e为棱数,f是面数,则
v-e+f=2-2p
p为欧拉示性数,例如
p=0 的多面体叫第零类多面体
p=1 的多面体叫第一类多面体
这里满足的是零类多面体,我们只要求出该图形的 点v,边e即可。 怎么求点v呢? 两部分一部分是原来的n-1个顶点,然后是交出来的,我们只要判断线段相交求直线交点即可,然偶可能会摇头重复的交点去掉,求边的话我们只要求出一个规范相交的点肯定会增加一条边,枚举点然后判断 点是否在线段上(除了端点),然偶求解即可。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0)
#define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("din.txt", "r", stdin)
#define Write() freopen("d.out", "w", stdout)
#define ll unsigned long long
#define keyTree (chd[chd[root][1]][0]) #define M 100007
#define N 317 using namespace std; const int inf = 0x7f7f7f7f;
const int mod = ; struct Point
{
double x,y;
Point(double tx = ,double ty = ) : x(tx),y(ty){}
};
typedef Point Vtor; Vtor operator + (Vtor A,Vtor B) { return Vtor(A.x + B.x,A.y + B.y); }
Vtor operator - (Point A,Point B) { return Vtor(A.x - B.x,A.y - B.y); }
Vtor operator * (Vtor A,double p) { return Vtor(A.x*p,A.y*p); }
Vtor operator / (Vtor A,double p) { return Vtor(A.x/p,A.y/p); }
const double eps = 1e-;
int dcmp(double x) { if (fabs(x) < eps) return ; else return x > ? : -; }
bool operator < (Point A,Point B) { return A.x < B.x || (A.x == B.x && A.y < B.y); }
bool operator == (Point A,Point B) { return dcmp(A.x - B.x) == && dcmp(A.y - B.y) == ; } double Dot(Vtor A,Vtor B) { return A.x*B.x + A.y*B.y; }
double Length(Vtor A) { return sqrt(Dot(A,A)); }
double Angle(Vtor A,Vtor B) { return acos(Dot(A,B)/Length(A)/Length(B)); }
double Cross(Vtor A,Vtor B) { return A.x*B.y - A.y*B.x; }
double Area2(Point A,Point B,Point C) { return Cross(B - A,C - A); }
Vtor Rotate(Vtor A,double rad) { return Vtor(A.x*cos(rad) - A.y*sin(rad),A.x*sin(rad) + A.y*cos(rad)); }
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ bool SegmentPI(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*c2) < && dcmp(c3*c4) < ; }
bool OnSegment(Point p,Point a1,Point a2)
{
return dcmp(Cross(a2 - p, a1 - p)) == && dcmp(Dot(a2 - p,a1 - p)) < ;
}
Point GetLineIn(Point P,Vtor v,Point Q,Vtor w)
{
Vtor u = P - Q;
double t = Cross(w,u)/Cross(v,w);
return P + v*t;
}
Point P[N],v[N*N];
int n; int main()
{ Read();
int Ei,Vi;
int cas = ;
while (~scanf("%d",&n))
{
if (!n) break;
Vi = ;
for (int i = ; i < n; ++i)
scanf("%lf%lf",&P[i].x,&P[i].y),v[Vi++] = P[i]; Ei = --n;
for (int i = ; i < n; ++i)
{
for (int j = i + ; j < n; ++j)
{
if (SegmentPI(P[i],P[i + ],P[j],P[j + ]))
{
v[Vi++] = GetLineIn(P[i],P[i + ] - P[i],P[j],P[j + ] - P[j]);
}
}
}
sort(v, v + Vi);
Vi = unique(v,v + Vi) - v;
for (int i = ; i < Vi; ++i)
{
for (int j = ; j < n; ++j)
{
if (OnSegment(v[i],P[j],P[j + ])) Ei++;
}
}
// printf("%d %d\n",Vi,Ei);
printf("Case %d: There are %d pieces.\n",cas++,Ei - Vi + );
} return ;
}
pku 2284 That Nice Euler Circuit的更多相关文章
- poj 2284 That Nice Euler Circuit 解题报告
That Nice Euler Circuit Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 1975 Accepted ...
- ●POJ 2284 That Nice Euler Circuit
题链: http://poj.org/problem?id=2284 题解: 计算几何,平面图的欧拉定理 欧拉定理:设平面图的定点数为v,边数为e,面数为f,则有 v+f-e=2 即 f=e-v+2 ...
- POJ 2284 That Nice Euler Circuit (LA 3263 HDU 1665)
http://poj.org/problem?id=2284 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&a ...
- 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
题意: 给出一个图,有的边是有向边,有的是无向边.试找出一条欧拉回路. 分析: 按照往常的思维,遇到混合图,我们一般会把无向边拆成两条方向相反的有向边. 但是在这里却行不通了,因为拆成两条有向边的话, ...
- UVA 10735 Euler Circuit 混合图的欧拉回路(最大流,fluery算法)
题意:给一个图,图中有部分是向边,部分是无向边,要求判断是否存在欧拉回路,若存在,输出路径. 分析:欧拉回路的定义是,从某个点出发,每条边经过一次之后恰好回到出发点. 无向边同样只能走一次,只是不限制 ...
- UVA-10735 - Euler Circuit(混合欧拉回路输出)
题意:给你一个图,有N个点,M条边,这M条边有的是单向的,有的是双向的. 问你能否找出一条欧拉回路,使得每条边都只经过一次! 分析: 下面转自别人的题解: 把该图的无向边随便定向,然后计算每个点的入度 ...
- Uva 1342 - That Nice Euler Circuit
Little Joey invented a scrabble machine that he called Euler, after the great mathematician. In his ...
随机推荐
- 【BZOJ2007】[Noi2010]海拔 对偶图最短路
[BZOJ2007][Noi2010]海拔 Description YT市是一个规划良好的城市,城市被东西向和南北向的主干道划分为n×n个区域.简单起见,可以将YT市看作 一个正方形,每一个区域也可看 ...
- Activity 设置切换动画
extends://blog.csdn.net/luohaowang320/article/details/42124225 | http://blog.csdn.net/xuewater/artic ...
- thinkCMF的使用!
第一次使用 thinkCMF:在此记录下使用的过程! 后台登录: http://thinkcmf.fyz.com/public/admin 前台:控制器 前台控制器的模板:
- Java虚拟机规范----JVM体系结构
一.Java平台的结构图 二.JVM与JRE.JDK关系? JVM:Java Virtual Machine(Java虚拟机),负责执行符合规范的Class文件 JRE:Java Runtime En ...
- JavaCSV之读CSV文件
Java在进行数据处理,有时候难免有进行CSV文件的操作,这里采用了JavaCSV读CSV文件. 1.准备工作 (1)第三方包库下载地址:https://sourceforge.net/project ...
- Oracle安装部署之 timesten install on redhat6.5
一.安装前检查 [root@localhost ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.5 (San ...
- 表单(中)-EasyUI Combogrid 组合网格、EasyUI Numberbox 数字框、EasyUI Datebox 日期框、EasyUI Datetimebox 日期时间框、EasyUI Calendar 日历
EasyUI Combogrid 组合网格 扩展自 $.fn.combo.defaults 和 $.fn.datagrid.defaults.通过 $.fn.combogrid.defaults 重写 ...
- PHP对象转数组
Solution json_decode( json_encode( $obj ), true ): But why?You should have a look at the function na ...
- AtCoder Grand Contest 030 Solution
A - Poisonous Cookies 签到. #include <bits/stdc++.h> using namespace std; #define ll long long l ...
- hdu5184 数论证明
这题说的给了一个整数n 和一串的括号, 那么要我们计算 最后有n/2对括号的 方案数有多少. 我们可以先预先判断一些不可能组成正确括号对的情况, 然后我们可以将这个问题转化到二维平面上, 令 m = ...