【TOJ 3005】Triangle(判断点是否在三角形内+卡精度)
描述
Given the coordinates of the vertices of a triangle,And a point. You just need to judge whether the point is in the Triangle.
输入
The input contains several test cases. For each test case, only line contains eight integer numbers , describing the coordinates of the triangle and the point. All the integer is in range of [-100 , 100].
The end of the input is indicated by a line containing eight zeros separated by spaces.
输出
For each test case , if the point is inside of the triangle ,please output the string ”YES”, else output the string “NO”. You just need to follow the following examples.
样例输入
0 0 4 0 0 4 3 1
0 0 4 0 0 4 1 2
0 0 4 0 0 4 -1 -1
0 0 0 0 0 0 0 0
样例输出
NO
YES
NO
思路:
通过判断3个小三角形面积是否等于大三角形面积即可,这道题卡精度,要控制误差在1e-9。
#include<bits/stdc++.h>
using namespace std;
struct node{
int x,y;
}a,b,c,p;
double edge(int x1,int y1,int x2,int y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
double area(int x1,int y1,int x2,int y2,int x3,int y3)
{
double A=edge(x1,y1,x2,y2);
double B=edge(x1,y1,x3,y3);
double C=edge(x3,y3,x2,y2);
double L=(A+B+C)*1.0/;
return fabs(sqrt(L*(L-A)*(L-B)*(L-C)));
}
bool check(double a,double b,double c,double p)
{
if(a==||b==||c==)
return false;
if(fabs(a+b+c-p)<=1e-)
return true;
return false;
}
int main()
{
while(cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y>>p.x>>p.y,a.x||a.y||b.x||b.y||c.x||c.y||p.x||p.y)
{
double s=area(a.x,a.y,b.x,b.y,c.x,c.y);
double abp=area(a.x,a.y,b.x,b.y,p.x,p.y);
double acp=area(a.x,a.y,c.x,c.y,p.x,p.y);
double bcp=area(c.x,c.y,b.x,b.y,p.x,p.y); if(check(abp,acp,bcp,s))
printf("YES\n");
else printf("NO\n");
}
return ;
}
【TOJ 3005】Triangle(判断点是否在三角形内+卡精度)的更多相关文章
- hrbustoj 1142:围困(计算几何基础题,判断点是否在三角形内)
围困 Time Limit: 1000 MS Memory Limit: 65536 K Total Submit: 360(138 users) Total Accepted: 157(12 ...
- 2D空间中判断一点是否在三角形内
要注意如果是XY坐标轴的2D空间,要取差乘分量z而不是y. 实现原理是,将三角形ABC三个边(AB,BC,CA)分别与比较点判断差乘,如果这3个差乘结果表示的方向一致,说明就在三角形内. 效果: 代码 ...
- Triangle - POJ 2954(求三角形内的格子点的个数)
Pick公式:平面上以格子点为顶点的简单多边形的面积=边上的点数/2+内部的点数+1. 代码如下: -------------------------------------------------- ...
- Project Euler 102:Triangle containment 包含原点的三角形
Triangle containment Three distinct points are plotted at random on a Cartesian plane, for which -10 ...
- poj 2954 Triangle 三角形内的整点数
poj 2954 Triangle 题意 给出一个三角形的三个点,问三角形内部有多少个整点. 解法 pick's law 一个多边形如果每个顶点都由整点构成,该多边形的面积为\(S\),该多边形边上的 ...
- 【Leetcode】判断平面中1个点是否落在三角形内
参考资料: 题目: https://blog.csdn.net/dongtinghong/article/details/78657403 符号重载: https://blog.csdn.net/cd ...
- C 语言实例 - 判断三边能否构成三角形
原理: 要判断输入的三条边能否够成三角形,只需满足条件两边之和大于第三边即可. #include<stdio.h> int main() { printf("请输入三个边长:\n ...
- hrbustoj 1429:凸多边形(计算几何,判断点是否在多边形内,二分法)
凸多边形 Time Limit: 2000 MS Memory Limit: 65536 K Total Submit: 130(24 users) Total Accepted: 40(1 ...
- SGU 253 Theodore Roosevelt 快速判断点是否在凸包内
http://acm.sgu.ru/problem.php?contest=0&problem=253 题意简单易懂...给你n个点的凸包(经测试已经是极角序)...判断m个点是否在凸包内.. ...
随机推荐
- caffe-windows中classification.cpp的源码阅读
caffe-windows中classification.cpp的源码阅读 命令格式: usage: classification string(模型描述文件net.prototxt) string( ...
- javascript12个你必须掌握的技能
网站建设的时候,作为码农,总喜欢写一些高效且省事的代码,这里,dbestech为你提供关于JavaScript的使用技巧点. 1. 空(null, undefined)验证 当我们创建了一个新的变量, ...
- 原生js实现雪花飘落效果
雪花飘落的效果实现步骤:1.使用setInterval定时器每800毫秒创建一个雪花:2.把每一个雪花作为参数传进动态下落的方法中即可. <style> *{padding: 0;marg ...
- Latest SoC
From: http://laoyaoba.com/ss6/html/68/n-505768.html 2014年国产ARM SoC芯片巡礼(上) 关注“集微网”,微信点播新闻.随要随有 来源: &l ...
- AngularJs整合ui-bootstrap以及ui-grid
1. ui-bootstrap 参考博客: http://www.cnblogs.com/pilixiami/p/5597634.html (这篇博客写的非常不错,值得推荐) angular-ui ...
- CSS3中的Flexbox弹性布局(二)
flexbox详解 flexbox的出现是为了解决复杂的web布局,因为这种布局方式很灵活.容器的子元素可以任意方向进行排列.此属性目前处于非正式标准. flex布局模型不同于块和内联模型布局,块和内 ...
- solidity语言3
#函数类型(function type) function (<parameter types>) {internal|external(public)} [pure|constant|v ...
- when create a table,then show error ora-00952 tablespace tsb_1 not exist
QUESTION:When create a table,then show error ora-00952 tablespace tsb_1 not exist. STEP: 1.select us ...
- Visual Studio 2012 未找到与约束 ContractName问题,及printf unsafe问题
1.用VS 2012 创建c++项目失败,提示未找到与约束 ContractName .............的错误 解决办法:下载VS 2012 补丁,很小的一个补丁,不过很管用 地址:http: ...
- python接口测试-项目实践(五) 实际结果与预期结果对比之 接口对比
五 与开发接口对比 1 分别将三个接口封装成三个函数,传入接口参数,返回提取并处理后的各字段. 拼接字符串作为单独的函数. def api_1(code): 发送请求获取响应 提取响应数据 响应数据转 ...