题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1665

题目:


一笔画,问能把平面划分成多少个区域

解题思路:


根据欧拉公式可知,只需要求出V和E,平面数目自然就能得出:

计算新顶点:在原n-1个顶点的基础上,再加上每条线段和它后面的线段规范相交(交点不是端点)的交点即可,可能会有重复的交点,记得去重

计算新边:在原n-1条边的基础上,再加上每个顶点对边的贡献,只要这个顶点在原始的n-1条边上(不在边的端点上),就有贡献。

学的太死了,不会应用,欧拉公式也忘了QAQ。

ac代码:


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 305;
const double eps = 1e-6;//eps用于控制精度,或者更高精度
const double pi = acos(-1.0);//pi
struct Point//点或向量
{double x, y;Point(double x = 0, double y = 0) :x(x), y(y) {}friend bool operator < (Point a, Point b){return a.x == b.x ? a.y < b.y : a.x < b.x;}
};
typedef Point Vector;
Vector operator + (Vector a, Vector b)//向量加法
{return Vector(a.x + b.x, a.y + b.y);
}
Vector operator - (Vector a, Vector b)//向量减法
{return Vector(a.x - b.x, a.y - b.y);
}
Vector operator * (Vector a, double p)//向量数乘
{return Vector(a.x * p, a.y * p);
}
Vector operator / (Vector a, double p)//向量数除
{return Vector(a.x / p, a.y / p);
}
int dcmp(double x)//精度三态函数(>0,<0,=0)
{if (fabs(x) < eps)return 0; //等于else return x < 0 ? -1 : 1;//小于,大于
}
bool operator == (const Point &a, const Point &b)//向量相等
{return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}
double Dot(Vector a, Vector b)//点积
{return a.x * b.x + a.y * b.y;
}
double Length(Vector a)//模
{return sqrt(Dot(a, a));
}
double Angle(Vector a, Vector b)//夹角,弧度制
{return acos(Dot(a, b) / Length(a) / Length(b));
}
double Cross(Vector a, Vector b)//外积
{return a.x * b.y - a.y * b.x;
}
Vector Rotate(Vector a, double rad)//逆时针旋转rad弧度
{return Vector(a.x*cos(rad) - a.y*sin(rad), a.x*sin(rad) + a.y*cos(rad));
}
Point GetLineIntersection(Point P, Vector v, Point Q, Vector w)//两直线的交点
{Vector u = P - Q;//QPdouble t = Cross(w, u) / Cross(v, w);return P + v * t;
}
bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2)
{double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - b1),c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1);return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0;
}
bool Onsegment(Point p, Point a1, Point a2)
{return dcmp(Cross(a1 - p, a2 - p)) == 0 && dcmp(Dot(a1 - p, a2 - p)) < 0;
}
int main()
{//freopen("/Users/zhangkanqi/Desktop/11.txt","r",stdin);int n, casee = 0;while(scanf("%d", &n) && n != 0){Point P[maxn], allp[maxn * maxn];for(int i = 0; i < n; i++){scanf("%lf %lf", &P[i].x, &P[i].y);allp[i] = P[i];}int v = n - 1, e = n - 1;//增加新顶点:for(int i = 0; i < n - 1; i++)for(int j = i + 1; j < n-1; j++)//j + 1 最大n-1if(SegmentProperIntersection(P[i], P[i + 1], P[j], P[j + 1]))//当前点和下一个点构成的边和它后面的边有无不是端点的交点allp[v++] = GetLineIntersection(P[i], P[i + 1] - P[i], P[j], P[j + 1] - P[j]);sort(allp, allp + v);v = unique(allp, allp + v) - allp;//增加新边:for(int i = 0; i < v; i++) //当前点在原始边上且不在端点for(int j = 0; j < n - 1; j++)if(Onsegment(allp[i], P[j], P[j + 1])) e++; //j + 1最大是n-1printf("Case %d: There are %d pieces.\n", ++casee, e + 2 - v);}return 0;
}

【HDU1665】That Nice Euler Circuit(欧拉公式+点在线段上判断(不在端点)+线段规范相交)相关推荐

  1. UVA10735 Euler Circuit题解

    原文链接:http://www.algorithmist.com/index.php/User:Sweepline/UVa_10735.cpp AC的C++语言程序: /* UVa 10735: fi ...

  2. 欧拉路径和欧拉回路(Euler Path and Euler Circuit)解释

    欧拉路径(欧拉回路)是图论非常重要的组成部分,欧拉路径是数学家欧拉在研究著名的德国哥尼斯堡(Koenigsberg)七桥问题时发现的.这一发现直接导致了一门新的理论研究的诞生-图论问题. 欧拉路径和欧 ...

  3. 损失2亿美元后续,Euler正与黑客进行链上谈判

    损失金额约2亿美元的Euler finance 闪电贷攻击已经成为2023年最大的去中心化金融黑客攻击.而在攻击事件发生一周后,Euler Finance 将与攻击者就资金返还问题进行谈判.这可能离追 ...

  4. UVA1342 That Nice Euler Circuit(ACM - ICPC 2004 Asia - Shanghai)(计算几何、欧拉定理)

    整理的算法模板合集: ACM模板 欧拉定理:设平面图的顶点数.边数和面数分别为V,E,F,则V+F-E=2. #include<bits/stdc++.h> using namespace ...

  5. Poj 2284 That Nice Euler Circuit

    人生第一道正儿八经的计算几何题...光消编译错误就弄了老半天,果然是够弱.. 题意大概是,给你N条线段,它们会构成一个一笔画的图形,给你先线段的顺序就是一笔画的顺序,线段可能相交但是不会重合 问你最后 ...

  6. LA 3263 That Nice Euler Circuit (2D Geometry)

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  7. ACM-ICPC模板整理

    备注其一:正在整理中,内容不全,部分代码测试次数较少或还未在OJ上尝试,可能会有代码不健全的情况发生. 备注其二:部分图片来自百度百科.wiki百科. 备注其三:CSDN一天只能上传十篇blog... ...

  8. 第7期:计算几何(持续更新中......)

    // 2022/01/22更新 更新内容主要为算法竞赛入门经典--训练指南(升级版)(刘汝佳.陈锋编著)第4章几何问题 1 二维几何基础 在平面坐标系下,向量和点一样,也用两个数x,y表示.第6章介绍 ...

  9. jiedai算法模板合集(正在肝2021.8.15)

    文章目录 基础模板 常用板子 数学题常用板子 输出挂 fread快读 高精度 分数类 打表压缩 基数排序 杂项 数据结构 树状数组 一维树状数组 二维树状数组 线段树 主席树 线段树合并/裂开 吉司机 ...

  10. 第26节 计算机网络知识

    第26节 计算机网络知识 计算机网络知识 1[单项选择题]Internet上的域名解析服务(DNS)完成域名与IP地址之间的翻译.执行域名服务的服务器被称为DNS 服务器.小张在Internet的某主 ...

最新文章

  1. 案例驱动python编程入门-python实现事件驱动
  2. 中國批准英特爾在東北投建晶片廠
  3. Java上机操作练习题-助力期末
  4. J2EE搭建Dynamic web SpringMVC工程404错误分析(一)
  5. mssql 远程无法连接mysql_在本地 怎么远程连接MSSQL数据库
  6. 【CodeForces - 474D】Flowers (线性dp)
  7. WebRTC-集成qsv硬解码实现
  8. 大一高数求极限的方法小结
  9. Failed to process import candidates for configuration class :Annotation-specified bean name ‘XXX‘ fo
  10. 计算机组成原理与体系结构 —— 南桥与北桥
  11. Transformer课程 业务对话机器人Rasa 3.x Reaching Out to the User
  12. Entity Component System与Entity Component
  13. vue树形权限菜单_vue树形菜单
  14. 学计算机c语言吗,学习C语言对学习计算机很重吗?
  15. 力扣练习——23 救生艇
  16. JAVA_数组的截取
  17. 蓝牙如何进行广播和扫描
  18. 2019暑假集训总结与记录
  19. 用Java输出100内的质数和合数(包含100)
  20. python习题练习

热门文章

  1. C#正则匹配、分组和替换
  2. zlib再windows下的编译
  3. lua 垃圾回收机制
  4. maven中,xml文件无法编译,想要在Java中写xml文件,需要配置xml信息,另外springBoot设置如何在资源目录下扫描xml文件
  5. python多维数据聚类可视化_基于python3的可视化数据聚类系统(k-means算法和k-中心点算法)...
  6. Android-path类整理
  7. CBD将建智慧城市管理平台
  8. 【STL记录】Containers--Lists
  9. 用P3P header解决iframe跨域访问cookie
  10. 给“大学生IT博客大赛”参赛博主的一封信