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. 其 ...
随机推荐
- ubuntu终端仿真程序和文件管理程序
1.SecureCRT是一款支持SSH(SSH1和SSH2)的终端仿真程序,简单的说是Windows下登录UNIX或Linux服务器主机的软件.可以理解为ubuntu下的Terminal. 如果Sec ...
- python eval()内置函数
python有一个内置函数eval(),可以将字符串进行运行. 通过help(eval)查看帮助文档 Help on built-in function eval in module builtins ...
- delphi基础篇之数据类型之一:1.简单类型(Simple)
1.简单类型(Simple) 简单类型包括实数类型(Real)和有序类型(Ordinal).有序类型又包括整数类型.字符类型.布尔类型.枚举类型和子界类型等. 1-1.有序类型 有序类型是一个有序数的 ...
- 拾遗:btrfs
#扫描 btrfs 文件系统btrfs device scan btrfs device scan /dev/sda #创建子卷或快照 btrfs subvolume create /mnt/btrf ...
- ATM+购物车结构
ATM+购物车 1.需求分析 2.程序设计及目录设计 3.编写程序 4.调试程序
- JDK在Win10与Ubuntu下的安装与配置
本文首发于cartoon的博客 转载请注明出处:https://cartoonyu.github.io/cartoon-blog 近段时间把自己电脑(win).虚拟机(Ubun ...
- java-day21
# DQL:查询语句 1. 排序查询 * 语法:order by 子句 * order by 排序字段1 排序方式1 , 排序字段2 排序方式2... ...
- Apache版hadoop编译
前言 做为大数据入门的基础,hadoop是每个大数据开发人员几乎不可避免的基础,目前hadoop已经发展到3.x.x版本,但当前企业使用的主流还是2.x.x版本,hadoop官网提供了编译后的had ...
- nuxt header 设置
1. nuxt.config.js 中配置全局 2. 在单页面设置单独
- C语言指针变量的长度
#include <stdio.h> int main() { /********************************************* * * 指针的长度:不同机器可 ...