Inside Triangle

https://hihocoder.com/contest/hiho225/problem/1

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

Determine if a point is inside a 2D triangle.

输入

The first line contains an integer T denoting the number of test case. (1 <= T <= 10)

The following T lines each contain 8 integers, Px, Py, Ax, Ay, Bx, By, Cx, Cy. P denotes the point. ABC denotes the triangle. The coordinates are within [-1000000, 1000000].

输出

For each test case output YES or NO denoting if the point is inside the triangle. Note that the point is considered inside the triangle if the point is just on some side of the triangle.

样例输入
2
0 1 -1 0 1 0 0 2
0 0 0 1 1 0 1 1
样例输出
YES
NO 用叉积判断是否同正负即可
 #include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
using namespace std; struct Point{
long long x,y;
}; long long Cross(Point P,Point A,Point B){
return (A.x-P.x)*(B.y-P.y)-(A.y-P.y)*(B.x-P.x);
} int main(){
int T;
scanf("%d",&T);
Point P,A,B,C;
while(T--){
scanf("%lld %lld %lld %lld %lld %lld %lld %lld",&P.x,&P.y,&A.x,&A.y,&B.x,&B.y,&C.x,&C.y);
long long ans1=Cross(A,B,P);
long long ans2=Cross(B,C,P);
long long ans3=Cross(C,A,P);
if((ans1<=&&ans2<=&&ans3<=)||(ans1>=&&ans2>=&ans3>=)){
puts("YES");
}
else{
puts("NO");
}
} }

Inside Triangle的更多相关文章

  1. hdu 1392凸包周长

    //用的自己的计算几何模板,不过比较慢嘿嘿 //要注意只有一个点和两个点 //Computational Geometry //by kevin_samuel(fenice) Soochow Univ ...

  2. C++ 凸包生成算法

    由于我的极差记忆力,我打算把这个破玩意先记下来.因为以后会有改动(Delaunay三角网生成算法),我不想把一个好的东西改坏了... 好吧-- 凸包生成算法,: 1.先在指定的宽(width)高(he ...

  3. 关于APIT定位算法的讨论

    关于APIT定位算法的讨论 [摘要]   无线传感器网络节点定位机制的研究中,基于距离无关的定位技术得到快速发展,其中基于重叠区域的APIT定位技术在实际环境中的定位精度高,被广泛研究和应用. [关键 ...

  4. Life of a triangle - NVIDIA's logical pipeline

    Home GameWorks Blog Life of a triangle - NVIDIA's logical pipeline   Life of a triangle - NVIDIA's l ...

  5. A trip through the Graphics Pipeline 2011_06_(Triangle) rasterization and setup

    Welcome back. This time we’re actually gonna see triangles being rasterized – finally! But before we ...

  6. 【POJ】2954 Triangle(pick定理)

    http://poj.org/problem?id=2954 表示我交了20+次... 为什么呢?因为多组数据我是这样判断的:da=sum{a[i].x+a[i].y},然后!da就表示没有数据了QA ...

  7. poj 2954 Triangle(Pick定理)

    链接:http://poj.org/problem?id=2954 Triangle Time Limit: 1000MS   Memory Limit: 65536K Total Submissio ...

  8. poj2954 Triangle

    地址:http://poj.org/problem?id=2954 题目: Triangle Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

  9. 【TOJ 3005】Triangle(判断点是否在三角形内+卡精度)

    描述 Given the coordinates of the vertices of a triangle,And a point. You just need to judge whether t ...

随机推荐

  1. InfluxDB 备份和恢复

    InfluxDB操作 . 显示数据库 > show databases > create database test > drop database test . 显示说有表 > ...

  2. 1034 Head of a Gang (30 分)

    1034 Head of a Gang (30 分) One way that the police finds the head of a gang is to check people's pho ...

  3. [UE4]运行时创建Actor

  4. RmNet,CDC-ECM ,NDIS,RNDIS区别

    RmNet和CDC-ECM区别:更像是两种拨号方式的区别,RmNet获取公网IP,ECD-ECM获取局域网IP. 在高通平台上,rmnet driver 和标准的CDC-ECM是有区别的,rmnet ...

  5. shell中使用函数

    函数定义.调用 $ cat te.sh #!/bin/bash # define a function test() { echo "This is a function." } ...

  6. ANA网络分析

    ANN网络分析 Mnist手写数字识别 Mnist数据集可以从官网下载,网址: http://yann.lecun.com/exdb/mnist/ 下载下来的数据集被分成两部分:55000行的训练数据 ...

  7. forward与redirect的区别

    1.从地址栏显示来说forward是服务器请求资源,服务器直接访问目标地址的URL,把那个URL的响应内容读取过来,然后把这些内容再发给浏览器.浏览器根本不知道服务器发送的内容从哪里来的,所以它的地址 ...

  8. SVN的使用----经历

    一,使用SVN down文件到本机 svn co path1 path2 co是checkout的简写 path1是源文件路径 path2是目标文件存放目录 比如::下面的方式是下载到当前目录. ++ ...

  9. Node fs, url, http 组合小型的服务器 ( 满足html请求, get, post 传值 )

    <script type="text/javascript"> /* * 引入模块 */ var http = require('http'); var url = r ...

  10. spring-boot + mybatis +pagehelper 使用分页

    转自:https://segmentfault.com/a/1190000015668715?utm_medium=referral&utm_source=tuicool 最近自己搭建一个sp ...