LA 3263 /// 欧拉定理 oj21860
题目大意:
n个端点的一笔画 第n个和第1个重合 即一笔画必定是闭合曲线
输出平面被分成的区域数
欧拉定理 V+F-E=2 即 点数+面数-边数=2 (这里的面数包括了外部)
#include <bits/stdc++.h>
using namespace std; const double eps=1e-;
double add(double a,double b) {
if(abs(a+b)<eps*(abs(a)+abs(b))) return ;
return a+b;
}
struct P {
double x,y;
P(){}
P(double _x,double _y):x(_x),y(_y){}
P operator - (P p) {
return P(add(x,-p.x),add(y,-p.y)); }
P operator + (P p) {
return P(add(x,p.x),add(y,p.y)); }
P operator / (double d) {
return P(x/d,y/d); }
P operator * (double d) {
return P(x*d,y*d); }
double dot (P p) {
return add(x*p.x,y*p.y); }
double det (P p) {
return add(x*p.y,-y*p.x); }
bool operator <(const P& p)const {
return x<p.x || (x==p.x && y<p.y);
}
bool operator ==(const P& p)const {
return abs(x-p.x)<eps && abs(y-p.y)<eps;
}
void read(){
scanf("%lf%lf",&x,&y); }
}p[], v[*], t;
int n; bool onSeg(P a,P b,P c) {
return (a-c).det(b-c)== && (a-c).dot(b-c)<=;
} /// c是否在线段ab上 包括端点
bool onSeg2(P a,P b,P c) {
return (a-c).det(b-c)== && (a-c).dot(b-c)<;
} /// c是否在线段ab上 不包括端点
P ins(P a,P b,P c,P d) {
return a+(b-a)*((d-c).det(c-a)/(d-c).det(b-a));
} /// 直线ab与cd的交点
bool insSS(P a,P b,P c,P d) {
if((a-b).det(c-d)==) { // 平行
return onSeg(a,b,c) || onSeg(a,b,d)
|| onSeg(c,d,a) || onSeg(c,d,b);
}
else {
t=ins(a,b,c,d);
return onSeg(a,b,t) && onSeg(c,d,t);
}
} /// 线段ab与cd是否相交 int main()
{
int o=;
while(~scanf("%d",&n)) {
if(n==) break;
for(int i=;i<n;i++)
p[i].read(), v[i]=p[i];
n--; // 最后一个和第一个重合 int c=n, e=n;
for(int i=;i<n;i++)
for(int j=i+;j<n;j++)
if(insSS(p[i],p[i+],p[j],p[j+]))
v[c++]=t; /// 若相交 加入交点 sort(v,v+c); // 排序需重载<
c=unique(v,v+c)-v; // 去重需重载== for(int i=;i<c;i++)
for(int j=;j<n;j++)
if(onSeg2(p[j],p[j+],v[i]))
e++; /// 线段上一个非端点的点可以把一条线段分成两段 printf("Case %d: There are %d pieces.\n",o++,e+-c);
} return ;
} //
LA 3263 /// 欧拉定理 oj21860的更多相关文章
- LA 3263 (欧拉定理)
欧拉定理题意: 给你N 个点,按顺序一笔画完连成一个多边形 求这个平面被分为多少个区间 欧拉定理 : 平面上边为 n ,点为 c 则 区间为 n + 2 - c: 思路: 先扫,两两线段的交点,存下来 ...
- LA 3263 欧拉定理
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- 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. 其 ...
随机推荐
- vbs 之 wscript
https://www.jb51.net/article/20919.htm '''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' ...
- 梯度下降:SGD vs Momentum vs NAG vs Adagrad vs Adadelta vs RMSprop vs Adam
原文地址:https://www.jianshu.com/p/7a049ae73f56 梯度下降优化基本公式:\({\theta\leftarrow\theta-\eta\cdot\nabla_\th ...
- C# 十六进制转换ASCII
string s = "这里放十六进制字符串"; byte[]buff=new byte[s.Length/2]; int ind ...
- jQuery 1.0 | 选择器 | 事件 | 操作样式 | 操作属性
使用jQuery: 1,下载jQuery http://jquery.com/download/ 2,引入jQuery文件 3,定义入口函数 <script src="jquery-1 ...
- 35-Ubuntu-组管理-01-添加组/删除组/确认组信息
组管理 提示: 创建组/删除组的终端命令都需要sudo执行,标准用户没有权限! 序号 命令 作用 01 sudo groupadd 组名 添加组 02 sudo groupdel 组名 删除组 03 ...
- spring mvc 配置后,web中的html页面报404,该怎么处理
问题描述: 在根目录webapp下的jsp页面可以通过url直接访问,而html页面就会报404错误. 解决方案1: 在spring-mvc.xml中添加如下配置: <!--将静态文件指定到某个 ...
- 获取url链接上的参数值的函数
function getUrlParam(name){ var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)'); var ...
- 标准 IO 测试 可以打开多少流
#include <stdio.h> #include <string.h> #include <errno.h> //trerror(errno) int mai ...
- python之pyquery 学习
pyquery是jQuery的Python实现,可以用以解析HTML网页的内容.官网文档:http://pythonhosted.org/pyquery/ 下载:https://pypi.python ...
- 笔记55 Mybatis快速入门(六)
相关概念介绍(一) 1.日志 有时候需要打印日志,知道mybatis执行了什么样的SQL语句,以便进行调试.这时,就需要开启日志,而mybatis自身是没有带日志的,使用的都是第三方日志,这里介绍如何 ...