题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1264

#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 欧拉定理的更多相关文章

  1. LA 3263 (欧拉定理)

    欧拉定理题意: 给你N 个点,按顺序一笔画完连成一个多边形 求这个平面被分为多少个区间 欧拉定理 : 平面上边为 n ,点为 c 则 区间为 n + 2 - c: 思路: 先扫,两两线段的交点,存下来 ...

  2. LA 3263 /// 欧拉定理 oj21860

    题目大意: n个端点的一笔画 第n个和第1个重合 即一笔画必定是闭合曲线 输出平面被分成的区域数 欧拉定理 V+F-E=2 即 点数+面数-边数=2 (这里的面数包括了外部) #include < ...

  3. LA 3263 (平面图的欧拉定理) That Nice Euler Circuit

    题意: 平面上有n个端点的一笔画,最后一个端点与第一个端点重合,即所给图案是闭合曲线.求这些线段将平面分成多少部分. 分析: 平面图中欧拉定理:设平面的顶点数.边数和面数分别为V.E和F.则 V+F- ...

  4. LA 3263 That Nice Euler Circuit(欧拉定理)

    That Nice Euler Circuit Little Joey invented a scrabble machine that he called Euler, after the grea ...

  5. 简单几何(求划分区域) LA 3263 That Nice Euler Circuit

    题目传送门 题意:一笔画,问该图形将平面分成多少个区域 分析:训练指南P260,欧拉定理:平面图定点数V,边数E,面数F,则V + F - E =  2.那么找出新增的点和边就可以了.用到了判断线段相 ...

  6. LA 3263 平面划分

    Little Joey invented a scrabble machine that he called Euler, after the great mathematician. In his ...

  7. 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 ...

  8. LA 3263 好看的一笔画 欧拉几何+计算几何模板

    题意:训练指南260 #include <cstdio> #include <cstring> #include <algorithm> #include < ...

  9. 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. 其 ...

随机推荐

  1. 利用html+ashx实现aspx的功能

    最近准备学习下ASP.NET,初期在网上看了些视频教程,准备将自己学习的东西整理整理,留着日后可以参考参考. 本文采用了html.ashx实现aspx,实现了一个最简单的动态网页效果,开发环境是VS2 ...

  2. wpf 调用线程必须为sta 因为许多ui组件都需要

    解决 办法 public void SomeMethod() { var task = System.Windows.Application.Current.Dispatcher.BeginInvok ...

  3. ubuntu桌面变空白,或者只有壁纸,任务栏消失的解决办法

    原因:因为打开了桌面特效的原因,但设置不合导致的. 解决方法:方法一:1.按住Ctrl+Alt+F1切换到字符终端下,输入用户名和密码登录2.输入以下命令删除出错的Compiz配置文件相关目录:rm ...

  4. 115个Java面试题和答案——终极列表

    from http://www.importnew.com/10980.html#collection http://www.importnew.com/11028.html 下面的章节分为上下两篇, ...

  5. jstl--c:choose标签

    今天使用c:choose标签,一直报错: 严重: Servlet.service() for servlet CheckIncome threw exceptionorg.apache.jasper. ...

  6. 浅谈KMP算法及其next[]数组

    KMP算法是众多优秀的模式串匹配算法中较早诞生的一个,也是相对最为人所知的一个. 算法实现简单,运行效率高,时间复杂度为O(n+m)(n和m分别为目标串和模式串的长度) 当字符串长度和字符集大小的比值 ...

  7. stat 的名字接口

    File::stat - stat 的名字接口 名字为:dev, ino, mode, nlink, uid, gid, rdev, size, atime, mtime, ctime, blksiz ...

  8. sql server 数据分页显示。

    select [ID] ,[StockApplyCode] ,[RcCode] ,[LabCenterCode] ,[LabGroupCode] ,[LabGroupName] ,[Barcode] ...

  9. jQuery网页加载进度条插件

    jquery.pace.js会自动监测你的Ajax请求,事件循环滞后,记录您的页面上准备状态和元素来决定的进度情况. 将pace.js和主题css的添加到您的网页! pace.js会自动监测你的Aja ...

  10. bzoj1038: [ZJOI2008]瞭望塔

    Description 致力于建设全国示范和谐小村庄的H村村长dadzhi,决定在村中建立一个瞭望塔,以此加强村中的治安.我们将H村抽象为一维的轮廓.如下图所示 我们可以用一条山的上方轮廓折线(x1, ...