Inside Triangle
Inside Triangle
https://hihocoder.com/contest/hiho225/problem/1
描述
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的更多相关文章
- hdu 1392凸包周长
//用的自己的计算几何模板,不过比较慢嘿嘿 //要注意只有一个点和两个点 //Computational Geometry //by kevin_samuel(fenice) Soochow Univ ...
- C++ 凸包生成算法
由于我的极差记忆力,我打算把这个破玩意先记下来.因为以后会有改动(Delaunay三角网生成算法),我不想把一个好的东西改坏了... 好吧-- 凸包生成算法,: 1.先在指定的宽(width)高(he ...
- 关于APIT定位算法的讨论
关于APIT定位算法的讨论 [摘要] 无线传感器网络节点定位机制的研究中,基于距离无关的定位技术得到快速发展,其中基于重叠区域的APIT定位技术在实际环境中的定位精度高,被广泛研究和应用. [关键 ...
- 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 ...
- 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 ...
- 【POJ】2954 Triangle(pick定理)
http://poj.org/problem?id=2954 表示我交了20+次... 为什么呢?因为多组数据我是这样判断的:da=sum{a[i].x+a[i].y},然后!da就表示没有数据了QA ...
- poj 2954 Triangle(Pick定理)
链接:http://poj.org/problem?id=2954 Triangle Time Limit: 1000MS Memory Limit: 65536K Total Submissio ...
- poj2954 Triangle
地址:http://poj.org/problem?id=2954 题目: Triangle Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- 【TOJ 3005】Triangle(判断点是否在三角形内+卡精度)
描述 Given the coordinates of the vertices of a triangle,And a point. You just need to judge whether t ...
随机推荐
- tomcat 加载顺序 web.xml文件详解
一. 1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点. 2.紧急着,容创建一个Se ...
- [UE4]解析json数据
正常的json对象是可以使用单引号的,但是在UE4中的json解析,不能如下使用单引号: {‘name’:'张三'} 而是要使用双引号写成: {"name":"张三&qu ...
- DOS 批处理命令For循环命令详解
for命令是一种对一系列对象依次循环执行同一个或多个命令的在命令行或批处理中运行的命令,结合一些Windows管理中的程序后,其处理功能强大.应用灵活方便程度令人刮目相看 for命令是一种对一系列 ...
- node实现缓存
内容: 1.缓存基本原理 2.node实现缓存 1.缓存基本原理 第一重要.缓存策略: cache-control:用于控制缓存,常见的取值有private.no-cache.max-age.must ...
- 搭建 yum 仓库
翻译来自:https://wiki.centos.org/HowTos/CreateLocalRepos 本地仓库 http 仓库 测试 Steps: 1.把rpm包放在一个目录中.可以根据需要在该目 ...
- JoinableQueue---创建可连接的共享进程队列
创建可连接的共享进程队列.这就像是一个Queue对象,但队列允许项目的使用者通知生产者项目已经被成功处理. 通知进程是使用共享的信号和条件变量来实现的. from multiprocessing im ...
- git常用命令,冲突
使用多个仓库git push cangkuming fenzhiming删除远程仓库 git push 远程仓库名 :删除目标分支 # 需要先删除本地目标分支 git pull <远程主机名&g ...
- c++官方文档-class
#include <iostream> using namespace std; class Circle { double radius; public: Circle(double r ...
- 温故而知新-PHP文件操作函数
1 文件操作流程 打开文件->读取或者写入文件->关闭文件 fopen->fread,fwrite->fclose fopen可以打开ftp或者http协议的文件,前提示对方支 ...
- sql 随机取数
Sql server: select top 10 * from 表 order by newid()Access: SELECT top 10 * FROM 表 ORDER BY ...