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 ...
随机推荐
- Redis字符串类型的操作
set key value [ex 秒数] / [px 毫秒数] [nx] /[xx] 如: set a 1 ex 10 , 10秒有效 Set a 1 px 9000 , 9秒有效 注: 如果ex ...
- 设备加速传感器(accelerometer) ---- HTML5+
模块:Accelerometer Accelerometer模块管理设备加速度传感器,用于获取设备加速度信息,包括x(屏幕水平方向).y(垂直屏幕水平方向).z(垂直屏幕平面方向)三个方向的加速度信息 ...
- 最小生成树的变形(次小生成树hdu4081)
hdu4081 Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- JavaIOC框架篇之Spring Framework
欢迎查看Java开发之上帝之眼系列教程,如果您正在为Java后端庞大的体系所困扰,如果您正在为各种繁出不穷的技术和各种框架所迷茫,那么本系列文章将带您窥探Java庞大的体系.本系列教程希望您能站在上帝 ...
- Code Forces 652D Nested Segments(离散化+树状数组)
Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- java 中的& &&区别以及 C++ 中& &&的区别
java中的 & &&两个运算符 (1).&在java中称做: 逻辑与 判断boolean类型,只有两者都是true时,才会返回true 举例: boolean b1= ...
- vs 开发常用快捷键
alt+shift+enter 编辑区最大化ctrl+] 括号匹配 ctrl+j 强迫智能感知ctrl+shift+空格 强迫智能感知(参数) ctrl+k+d ...
- Qt:小项目仿QQ修改头像界面,技术点记录
最近写了一个修改头像功能的UI,布局参考了QQ目前的修改头像界面.如下图 这里主要说明一下两个地方的技术:1.头像图片上层的遮罩层,圆形外部为灰色,内部为全透明:2.上传图片宽高比例可以通过鼠标拖拽移 ...
- 转!!CMPP 网关错误码说明
http://www.163duanxin.com/msg/1753.htm CMPP错误码说明 与中国移动代码的对应关系. MI::zzzzSMSC返回状态报告的状态值为EXPIREDMJ:zz ...
- Python并行编程(十四):异步编程
1.基本概念 除了顺序执行和并行执行的模型以外,还有异步模型,这是事件驱动模型的基础.异步活动的执行模型可以只有一个单一的主控制流,能在单核心系统和多核心系统中运行. 在并发执行的异步模型中,许多任务 ...