题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21363

【思路】

欧拉定理:V+F-E=2。则F=E-V+2。

其中V E F分别代表平面图的顶点数,边数和面数。

涉及到判断线段是否有交点,直线求交点以及判断点是否在直线上的函数。注意求直线交点之前需要判断是否有交点,交点还需要去重。

【代码】

 #include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define FOR(a,b,c) for(int a=(b);a<(c);a++)
using namespace std; const double eps = 1e-;
int dcmp(double x) {
if(fabs(x)<eps) return ; else return x<? -:;
} struct Pt {
double x,y;
Pt(double x=,double y=):x(x),y(y) {};
};
typedef Pt vec; vec operator - (Pt A,Pt B) { return vec(A.x-B.x,A.y-B.y); }
vec operator + (vec A,vec B) { return vec(A.x+B.x,A.y+B.y); }
vec operator * (vec A,double p) { return vec(A.x*p,A.y*p); }
double Dot(vec A,vec B) { return A.x*B.x+A.y*B.y; }
double cross(vec A,vec B) { return A.x*B.y-A.y*B.x; }
bool operator < (const Pt& a,const Pt& b) {
return a.x<b.x || (a.x==b.x && a.y<b.y);
}
bool operator == (const Pt& a,const Pt& b) { // for unique
return dcmp(a.x-b.x)== && dcmp(a.y-b.y)==;
} Pt LineIntersection(Pt P,vec v,Pt Q,vec w) {
vec u=P-Q;
double t=cross(w,u)/cross(v,w);
return P+v*t;
}
bool SegIntersection(Pt a1,Pt a2,Pt b1,Pt 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)<;
// b1 b2在线段a1a2的两侧 a1 a2在线段b1b2的两侧 => 规范相交
}
bool OnSeg(Pt P,Pt a1,Pt a2) {
return dcmp(cross(a1-P,a2-P))== && dcmp(Dot(a1-P,a2-P))<;
} const int N = +;
Pt P[N],V[N*N];
int n; int main() {
int kase=;
while(scanf("%d",&n)== && n) {
FOR(i,,n)
scanf("%lf%lf",&P[i].x,&P[i].y) , V[i]=P[i];
n--;
int c=n,e=n;
FOR(i,,n) FOR(j,i+,n)
if(SegIntersection(P[i],P[i+],P[j],P[j+]))
V[c++]=LineIntersection(P[i],P[i+]-P[i],P[j],P[j+]-P[j]);
sort(V,V+c);
c=unique(V,V+c)-V;
FOR(i,,c) FOR(j,,n)
if(OnSeg(V[i],P[j],P[j+])) e++;
printf("Case %d: There are %d pieces.\n",++kase,e+-c);
}
return ;
}

UVAlive 3263 That Nice Euler Circuit(欧拉定理)的更多相关文章

  1. UVALive - 3263 That Nice Euler Circuit (几何)

    UVALive - 3263 That Nice Euler Circuit (几何) ACM 题目地址:  UVALive - 3263 That Nice Euler Circuit 题意:  给 ...

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

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

  3. uvalive 3263 That Nice Euler Circuit

    题意:平面上有一个包含n个端点的一笔画,第n个端点总是和第一个端点重合,因此团史一条闭合曲线.组成一笔画的线段可以相交,但是不会部分重叠.求这些线段将平面分成多少部分(包括封闭区域和无限大区域). 分 ...

  4. UVALive 3263: That Nice Euler Circuit (计算几何)

    题目链接 lrj训练指南 P260 //==================================================================== // 此题只需要考虑线 ...

  5. UVALi 3263 That Nice Euler Circuit(几何)

    That Nice Euler Circuit [题目链接]That Nice Euler Circuit [题目类型]几何 &题解: 蓝书P260 要用欧拉定理:V+F=E+2 V是顶点数; ...

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

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

  7. hdu 1665 That Nice Euler Circuit(欧拉定理)

    输入n个点,然后从第一个点开始,依次链接点i->点i+1,最后回到第一点(输入中的点n),求得到的图形将平面分成了多少部分. 根据欧拉定理 v_num + f_num - e_num = 2可知 ...

  8. poj2284 That Nice Euler Circuit(欧拉公式)

    题目链接:poj2284 That Nice Euler Circuit 欧拉公式:如果G是一个阶为n,边数为m且含有r个区域的连通平面图,则有恒等式:n-m+r=2. 欧拉公式的推广: 对于具有k( ...

  9. POJ2284 That Nice Euler Circuit (欧拉公式)(计算几何 线段相交问题)

                                                          That Nice Euler Circuit Time Limit: 3000MS   M ...

随机推荐

  1. angularjs中异常处理

    1.TypeError: Cannot read property '$valid' of undefined a. Add ng-submit attribute to the form: < ...

  2. A题笔记(9)

    No.2283 No.1387 vector<vector<char> > before, after; 可以创建一个容器的容器,注意 char 后的两个 “>” ,之间 ...

  3. SQL性能优化没有那么神秘

    经常听说SQL Server最难的部分是性能优化,不禁让人感到优化这个工作很神秘,这种事情只有高手才能做.很早的时候我在网上看到一位高手写的博客,介绍了SQL优化的问题,从这些内容来看,优化并不都是一 ...

  4. ios开发中MVC模式的理解

    MVC是80年代出现的一种软件设计模式,是模型(model),视图(view)和控制(Controller)的缩写. 其中Model的主要功能包括业务逻辑的处理以及数据的访问,这是应用程序的主体部分. ...

  5. ZOJ 1733 Common Subsequence(LCS)

    Common Subsequence Time Limit: 2 Seconds      Memory Limit: 65536 KB A subsequence of a given sequen ...

  6. SVM技法

    PLA不管胖瘦,SVM喜欢胖的 fewer dichotomies=> small VC 演算法的VC dimension shatter 掉3个点 如果限制胖瘦,两个点都shatter不掉 喜 ...

  7. Android Studio中JNI -- 2 -- 编写c文件

    继上一篇,我们在native接口中编写了2个方法 生成的相应.h文件 这时,需要我们自己去完善.c文件 /* DO NOT EDIT THIS FILE - it is machine generat ...

  8. 防范DDOS攻击脚本

    防范DDOS攻击脚本 #防止SYN攻击 轻量级预防 iptables -N syn-flood iptables -A INPUT -p tcp --syn -j syn-flood iptables ...

  9. sql 建立数据库,表格,索引,主键

    ---- 数据库: `message_db`-- -- --------------------------------------------------------create database ...

  10. Spring面试笔记

    1. Spring工作机制及为什么要用?Spring 是一个开源框架,是为了解决企业应用程序开发复杂性而创建的.Spring既是一个AOP框架,也是一IOC容器.SpringFramework的组成: ...