题目大意:

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的更多相关文章

  1. LA 3263 (欧拉定理)

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

  2. LA 3263 欧拉定理

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

  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. 带头结点的循环单链表----------C语言

    /***************************************************** Author:Simon_Kly Version:0.1 Date: 20170520 D ...

  2. JAVA调用R脚本

    0 前言R是一种非常方便易用的绘图.统计分析.ML算法设计方面的脚本语言.实际中有这样一种场景:算法工程师用R搭建了机器学习算法模型,想用于javaweb之中但是又不想重新用java写一遍算法模型,那 ...

  3. winform textbox 不能唤醒windows 平板的软键盘解决办法

    这个问题,研究了将近两个小时,baidu,google,好大一会,windows 平板本身的应用程序,必须浏览器,notepad都是可以自动唤起软键盘的,但是我的winfrom 程序就是不可以,起先怀 ...

  4. Flyway 学习时遇到的错误

    错误一: No plugin found for prefix 'flyway' in the current project and in the plugin groups  找不到Flyway插 ...

  5. linux部署tomcat项目

    unzip apache-tomcat-7.0.55-windows- x64.zip     解压zip文件 chmod +x startup.sh shutdown.sh catalina.sh ...

  6. Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实 现)interface(接口

    匿名的内部类是没有名字的内部类.不能extends(继承) 其它类,但一个内部类可以作为一个接口,由另一个内部类实现

  7. Vue for循环 例子

    demo <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf- ...

  8. Vue登录登出以及JWT认证

    数据模型 主要用户名,密码,邮箱,头像,身份 const mongoose = require('mongoose') const schema = new mongoose.Schema({ use ...

  9. Spring Boot 2.X 对 web 的开发支持(二)

    Spring Boot 2.X 对 web 的支持开发 上章节的 Spring Boot 的入门案例,我们感受到 Spring Boot 简单的配置即可运行项目. 今天了解 Spring Boot 对 ...

  10. ReadWriteLock 如何使用?

    QReadWriteLock从名字看就知道是读写锁的意思.和QMutex一样,QReadWriteLock也是线程同步的一种工具.那么它有什么用呢?和QMutex又有什么区别呢?写个例子瞧一瞧. 特点 ...