LA 3263 欧拉定理
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = ;
const int maxe = ;
const int INF = 0x3f3f3f; 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 - (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);
}
const double eps = 1e-;
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) == ;
} ///向量(x,y)的极角用atan2(y,x);
double Dot(Vector A, Vector B){ return A.x*B.x + A.y*B.y; }
double Length(Vector A) { return sqrt(Dot(A,A)); }
double Angle(Vector A, Vector B) { return acos(Dot(A,B) / Length(A) / Length(B)); } double Cross(Vector A, Vector B) { return A.x*B.y - A.y * B.x; }
double Area2(Point A,Point B,Point C) { return Cross(B-A,C-A); } ///向量的逆时针旋转,rad 为旋转的角;
Vector Rotate(Vector A, double rad) { return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad)); }
///特殊的,下面函数计算向量的单位法向量,即左旋90,在长度归一化;
Vector Normal(Vector A){
double L = Length(A);
return Vector(-A.y/L, A.x/L);
} ///直线用参数式 P = P'+ t * v;P'为直线上一点,v为方向向量;
///t不受限制,为直线,t>0 为射线, 0=<t<=1为线段;
///推导暂时不会,下面计算直线P+tv和Q+tw的交点。调用前先确保两直线有唯一交点;即判定Cross(v,w) 非0;
Point GetLineIntersecion(Point P, Vector v,Point Q,Vector w){
Vector u = P - Q;
double t = Cross(w,u)/Cross(v,w);
return P + v*t;
} ///求点到直线的距离,利用h*|AB| == AB(向量) * AP(向量);
double DistanceToLine(Point P,Point A,Point B){
Vector v1 = B - A, v2 = P - A;
return fabs(Cross(v1,v2)) / Length(v1);
} ///求点P到线段AB的距离,先看Q点在线段外还是内;利用点积就可以,
double DistanceToSegment(Point P,Point A,Point B){
if(A == B) return Length(P-A);
Vector v1 = B - A,v2 = P - A,v3 = P - B;
if(dcmp(Dot(v1,v2)) < ) return Length(v2);
else if(dcmp(Dot(v1,v3) > )) return Length(v2);
else return fabs(Cross(v1,v2))/Length(v1);
}
///如果要求Q的话:(当然满足Q在线段内),由公式Dot(v,P-(A+t'*v)) == 0 推出;
Point GetLineProjection(Point P,Point A,Point B){
Vector v = B - A;
return A + v * (Dot(v,P-A)/Dot(v,v));
} ///判定线段是否规范相交;
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) < ;
}
///如果允许在端点处相交:c1和c2都是0,表示两线段共线;如果只有其中一个为0,则一条线段的端点在另一条线段上;
///下面的代码判断一个点P是否在一条线段AB上(不包括A,B点);
bool OnSegment(Point P,Point A,Point B){
return dcmp(Cross(A-P,B-P)) == && dcmp(Dot(P-A,P-B)) < ;
} ///多边形
///求面积
double PolygonArea(Point* p,int n){
double area = ;
for(int i=;i<n-;i++){
area += Cross(p[i]-p[],p[i+]-p[]);
}
return area/;
} int main()
{
//freopen("E:\\acm\\input.txt","r",stdin);
//freopen("E:\\acm\\output.txt","w",stdout); Point p[maxn],v[maxn*maxn];
int n,T=;
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++] = GetLineIntersecion(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++;
printf("Case %d: There are %d pieces.\n",T++,ecnt+-vcnt);
} return ;
}
LA 3263 欧拉定理的更多相关文章
- LA 3263 (欧拉定理)
欧拉定理题意: 给你N 个点,按顺序一笔画完连成一个多边形 求这个平面被分为多少个区间 欧拉定理 : 平面上边为 n ,点为 c 则 区间为 n + 2 - c: 思路: 先扫,两两线段的交点,存下来 ...
- LA 3263 /// 欧拉定理 oj21860
题目大意: n个端点的一笔画 第n个和第1个重合 即一笔画必定是闭合曲线 输出平面被分成的区域数 欧拉定理 V+F-E=2 即 点数+面数-边数=2 (这里的面数包括了外部) #include < ...
- LA 3263 (平面图的欧拉定理) That Nice Euler Circuit
题意: 平面上有n个端点的一笔画,最后一个端点与第一个端点重合,即所给图案是闭合曲线.求这些线段将平面分成多少部分. 分析: 平面图中欧拉定理:设平面的顶点数.边数和面数分别为V.E和F.则 V+F- ...
- 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.那么找出新增的点和边就可以了.用到了判断线段相 ...
- LA 3263 平面划分
Little Joey invented a scrabble machine that he called Euler, after the great mathematician. In his ...
- 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 ...
- LA 3263 好看的一笔画 欧拉几何+计算几何模板
题意:训练指南260 #include <cstdio> #include <cstring> #include <algorithm> #include < ...
- 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. 其 ...
随机推荐
- EntityFramework在root目录web.config中的配置设置
未找到具有固定名称“System.Data.SqlClient”的 ADO.NET 提供程序的实体框架提供程序.请确保在应用程序配置文件的“entityFramework”节中注册了该提供程序.有关详 ...
- C# Chart圖標綁定
开发软件为VS2010 免去了安装插件之类的麻烦. 最终效果图: 饼状图: 前台设置:设置参数为: :Titles, 添加一个序列,在Text中设置名字. :Series ,添加一个序列,选择Char ...
- ios strong weak 的区别 与 理解
先一句话总结:strong类保持他们拥有对象的活着,weak类他们拥有的对象被人家一牵就牵走,被人家一干就干死.(strong是一个好大哥所以strong,呵呵,weak是一个虚大哥所以weak,呵呵 ...
- SGU 181.X-Sequence
时间限制:0.5s 空间限制:4M 题意: 令X0=A, Xi=(a*Xi-1^2,b*Xi-1+c)%m; 求Xk,(0<=k<=109),(0<=a,b<=100),(1& ...
- 简单高效读写修改整个文本Slurp
语法: use File::Slurp; #标量环境下一次读取所有文本内容到标量中. my $text = read_file( 'filename' ) ; # 读取文本的所有行到数组中. my ...
- jQuery慢慢啃之属性(三)
1.attr(name|properties|key,value|fn)设置或返回被选元素的属性值. $("img").attr("src");//获取属性 $ ...
- js prototype __proto__ instanceof constructor
JS中有两个特殊的对象:Object与Function,它们都是构造函数,用于生成对象. Object.prototype是所有对象的祖先,Function.prototype是所有函数的原型,包括构 ...
- 【C#枚举】根据EnumName获取Value
public static int GetEnumValue(Type enumType, string enumName) { try { if (!enumType.IsEnum) throw n ...
- PHP时间戳和日期相互转换
在php中我们要把时间戳转换日期可以直接使用date函数来实现,如果要把日期转换成时间戳可以使用strtotime()函数实现,下面我来给大家举例说明. 1.php中时间转换函数 strtotime ...
- Notepad++ Shortcuts(Chinese and English Version)
Ctrl+C 复制Ctrl+X 剪切Ctrl+V 粘贴Ctrl+Z 撤消Ctrl+Y 恢复Ctrl+A 全选Ctrl+F 键查找对话框启动Ctrl+H 查找/替换对话框Ctrl+D 复制并粘贴当行 C ...