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 ...
随机推荐
- Egret3D初步笔记二 (Unity导出场景使用)
一 Scene 根据上一节的继续.在导入unity4.7.1_Egret3D_Dll.unitypackage后. 在Unity中双击打开Assets/Egret3D/Example下的Example ...
- Flash 用FLASH遮罩效果做图片切换效果
本教程是关于FLASH应用遮罩效果制作好看的图片切换效果.该教程选用FLASH遮罩中最简单的一种作为例子,当然你可以用自己的想象力来做出更多更好的图片动画.希望本教程能带你带来帮助. 让我们先看看效果 ...
- 三维凸包求重心到面的最短距离(HDU4273)
http://acm.hdu.edu.cn/showproblem.php?pid=4273 Rescue Time Limit: 2000/1000 MS (Java/Others) Memo ...
- 'Settings' object has no attribute 'TEMPLATE_DEBUG' 的解决方法
找到该Django项目下的settings文件,把 DEBUG = True 改为 DEBUG = False 就可以正常浏览显示了 参考:https://stackoverflow.com/ques ...
- 基于JDK1.8的String源码学习笔记
String,可能是学习Java一上来就学习的,经常用,但是却往往只是一知半解,甚至API有时也得现查.所以还是老规矩,倒腾源码. 一.java doc 这次首先关注String的doc,因为其实作为 ...
- OGG双向复制
注意:在进行如下配置之前,先在源数据库(原来的目标数据库)端添加辅助的redolog配置: 1.SQL> alter database add supplemental log dat ...
- 多线程下载图片,滑动tableView崩溃--资源抢夺问题
最近练习使用NSoperation模拟SDWebImage下载图片,发生了崩溃的问题,还专门写博客记录这件事情: http://www.cnblogs.com/tufei7/p/7074030.htm ...
- matplotlib-折线图、散点图
(一)折线图小结 1.设置图片大小(想要一个高清无码大图) # 图大小 plt.figure(figsize=(20, 8), dpi=80) 2.保存到本地 # 设置图片大小 plt.figure( ...
- stm8s 时钟库函数选择内部RC初始化
//本文选择16M内部RC震荡.分频为1 即系统时钟为16M void CLK_HSICmd(FunctionalState NewState) { /* Check the parameters * ...
- android 控件加圆角
1.新建一个radius_border.xml <shape xmlns:android="http://schemas.android.com/apk/res/android&quo ...