描述

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. 简单Java程序向实用程序的过度:二进制文件的读写

    File I/O中常见的文件读写: 1.字节流读写文本文件 FileInputStream; FileOutputStream; 2.字符流读写文本文件 FileReader; FileWriter; ...

  2. Python爬虫《http和https协议》

    一.HTTP协议 1.官方概念: HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文 ...

  3. Web前端面试指导(七):入职后的建议

    7.2 关于合同 签合同的时候,看公司要求,有些是3年,有些是5年,不要怕,签了就是了,真到想走的时候,提前说一声,随时可以走,不存在什么违约赔偿. 注意:你的合同和薪资都是属于保密的,不能让公司其他 ...

  4. checkbox中把选项文字与小圆圈关联上

    跳舞 唱歌 阅读 睡觉 <form><input id="1" type="checkbox" name="hobbies" ...

  5. 关于easyui 窗口位置的调整

    (一)easyui 默认的窗口位置 浏览器中间 (二)可直接在style里进行更改 <div id="news_dialog" class="easyui-wind ...

  6. 使用weinre调试Web应用及PhoneGap应用

    Web开发者经常使用Firefox的firebug或者Chrome的开发人员工具进行Web调试,包括针对JavaScript,DOM元素和CSS样式的调试.但是,当我们期望为移动Web站点或应用进行调 ...

  7. DB2数据库创建数据库操作过程

    /* author simon */ 例:数据库:NCDB2用户 :DB2ADMIN/DB2ADMIN备份库路径:D:/bank 一.恢复数据库1.启动数据库运行->db2cmd->db2 ...

  8. 动态获取Drawable图片资源

    比如Drawable中有一系列连续的图片,img_0.png, img_1.png, img_2.png ... 如果要动态获取这些图片,通过"R.drawable.img_x"的 ...

  9. Golang Gin 项目使用 Swagger

    Golang Gin 项目使用 Swagger 标签(空格分隔): Go 首先需要github.com/swaggo/gin-swagger和github.com/swaggo/gin-swagger ...

  10. ORACLE_TRIGGER

    PL/SQL TRIGGER Statement PL/SQL TRIGGER  Statement The trigger statemet is a especially stored proce ...