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. 其 ...
随机推荐
- jdk tomcat的项目版本一致操作
操作jdk版本以及tomcat版本:右键项目--buildpath--configure buildpath...---project Facets---libraries---add/选中remov ...
- java xmltojson jsontoxml
JSONObject.fromObject需要的有额外的6个包,必不可少,一定要注意: commons-beanutils-1.9.2.jar commons-collections-3.2 ...
- AndroidFine Error:Annotation processors must be explicitly declared now.
环境 Android Studio 3.0 Gradle 3.0.0 gradle 4.1 Error Error:Execution failed for task ':app:javaPreCom ...
- docker常用
1. docker 查看正在运行 2. docker 查看所有 3. docker 查看镜像 4. docker 运行使用 docker run --name 镜像名(自己起的镜像名字)-d(后台) ...
- C# 基于创建一个mysql 连接池
创建一个连接池操作类 using MySql.Data.MySqlClient; using System; using System.Collections.Generic; using Syste ...
- Web开发常规调试方法与常见问题分析
一.Web项目基本原理 现在的web项目大都已经前后端独立开发与部署. 前后端独立开发,一般是前端与后端通过web接口(常见的有RESTful与websocket)文档进行交流.前端开发人员先更具业务 ...
- 使用Kettle的命名参数动态执行作业
关于如何根据传入的不同参数,达到动态运行作业的目的,这里不介绍.只提供一个思路,就是不同的调度进程调度同一个Kettle文件时,传入了不同的参数,从而得到不同的数据. 如下图所示: 1. 先设置参数名 ...
- nginx 简单使用
一,下载 http://nginx.org/en/download.html 这个是我下载的windows版本 二,解压后目录 三,修改配置文件 (由于80端口很可能被 SQL Server Repo ...
- openwrt redis
2071 make V=s 2072 cd build_dir/target-x86_64_uClibc-0.9.33.2/root-x86/ cd package/network/services/ ...
- python编程学习day04
1.函数名是变量名 “=”是内存指向,等号赋值操作,内存指向操作 变量——可赋值,可作为列表元素 函数名可以作为返回值返回 函数名可作为参数传递 2.闭包 内层函数使用了外层函数的变量 作用:可以让一 ...