描述

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(判断点是否在三角形内+卡精度)的更多相关文章

  1. hrbustoj 1142:围困(计算几何基础题,判断点是否在三角形内)

    围困 Time Limit: 1000 MS     Memory Limit: 65536 K Total Submit: 360(138 users) Total Accepted: 157(12 ...

  2. 2D空间中判断一点是否在三角形内

    要注意如果是XY坐标轴的2D空间,要取差乘分量z而不是y. 实现原理是,将三角形ABC三个边(AB,BC,CA)分别与比较点判断差乘,如果这3个差乘结果表示的方向一致,说明就在三角形内. 效果: 代码 ...

  3. Triangle - POJ 2954(求三角形内的格子点的个数)

    Pick公式:平面上以格子点为顶点的简单多边形的面积=边上的点数/2+内部的点数+1. 代码如下: -------------------------------------------------- ...

  4. Project Euler 102:Triangle containment 包含原点的三角形

    Triangle containment Three distinct points are plotted at random on a Cartesian plane, for which -10 ...

  5. poj 2954 Triangle 三角形内的整点数

    poj 2954 Triangle 题意 给出一个三角形的三个点,问三角形内部有多少个整点. 解法 pick's law 一个多边形如果每个顶点都由整点构成,该多边形的面积为\(S\),该多边形边上的 ...

  6. 【Leetcode】判断平面中1个点是否落在三角形内

    参考资料: 题目: https://blog.csdn.net/dongtinghong/article/details/78657403 符号重载: https://blog.csdn.net/cd ...

  7. C 语言实例 - 判断三边能否构成三角形

    原理: 要判断输入的三条边能否够成三角形,只需满足条件两边之和大于第三边即可. #include<stdio.h> int main() { printf("请输入三个边长:\n ...

  8. hrbustoj 1429:凸多边形(计算几何,判断点是否在多边形内,二分法)

    凸多边形 Time Limit: 2000 MS    Memory Limit: 65536 K Total Submit: 130(24 users)   Total Accepted: 40(1 ...

  9. SGU 253 Theodore Roosevelt 快速判断点是否在凸包内

    http://acm.sgu.ru/problem.php?contest=0&problem=253 题意简单易懂...给你n个点的凸包(经测试已经是极角序)...判断m个点是否在凸包内.. ...

随机推荐

  1. Django组件——分页器(paginator)

    一.视图层 from django.shortcuts import render # Create your views here. from .models import Book from dj ...

  2. scss-null在@mixin传参中的应用

    可以给混合器声明参数,以便灵活的配置相关属性值,看如下scss代码: @mixin antzone-div($color, $font-size) { color:$color; font-size: ...

  3. 【阿里云产品公测】简单粗暴30S完成PTS测试配置附tornado服务器测试结果

    作者:阿里云用户morenocjm [阿里云产品公测]简单粗暴 30S完成PTS测试配置(附tornado服务器测试结果) -------------------------------------- ...

  4. JPA 使用 Specification 复杂查询和 Criteria 查询

    转自:https://blog.wuwii.com/jpa-specification.html 前言 JPA 给我们提供了基础的 CURD 的功能,并且用起来也是特别的方便,基本都是一行代码完成各种 ...

  5. Intent的简单使用

    主要实现Intent之间值得转递,如从AActivity到BActivity之间传一个数值,一个实体类,一个集合类 下面代码只要是实现对startActivityForResult的使用,用ABC 3 ...

  6. jquery mobile 自定义图标

    Jquery Mobile框架包含了一组最常用的移动应用程序所需的图标,为了减少下载的大小,Jquery Mobile包含的是的白色的图标sprite图片,并自动在图标后添加一个半透明的黑圈以确保在任 ...

  7. Eclipse 各版本名称的由来

    2001年11月7日 ,Eclipse 1.0发布 半年之后,2002年6月27日Eclipse进入了2.0时代.2.0时代的Eclipse经历了2.0和2.1两个大的版本.其中2.0在 之后又推出了 ...

  8. Java中long和Long有什么区别(转)

    Java的数据类型分两种:1.基本类型:long,int,byte,float,double,char2. 对象类型(类): Long,Integer,Byte,Float,Double,Char,S ...

  9. VS中bin,app_code,app_data,app_browser,app_GlobalResources等文件夹的作用 .

    1.  Bin文件夹 Bin文件夹包含应用程序所需的,用于控件.组件或者需要引用的任何其他代码的可部署程序集.该目录中存在的任何.dll文件将自动地链接到应用程序.如果在该文件夹中留有不用的或过期的文 ...

  10. 定时备份SQL Server数据库

    一.手动备份: 1.整个数据库备份:选择数据库 => 右键任务 => 备份: 2.导出一张表的框架:选择表 => 编写表脚本为 => CREATE到: 3.导出一张表的数据:  ...