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 ...
随机推荐
- httpclient httpcore jar包及源码
HttpClient HttpCore HttpComponents jar src download httpclient home help
- linux 添加secondary ip
linux下ip地址除了primary外,还有两种:1. ip alias(子接口)2. secondary ip(辅助ip) 都可在一块物理网卡上添加,alias由ifconfig添加,ifconf ...
- Linux命令详解-文件系统管理
1. 外部设备简介 (1.)硬盘的分类: IDE硬盘 ./dev/hda hdb,hdc… 分区后:/dev/hda1 /dev/hda2 scsi硬盘: /dev/sda sdb,sdc ...
- RAC 11.2的新特性
网格即插即用(GPnP) 网格即插即用帮助管理员来维护集群,以前增加或删除节点需要的一些手动操作的步骤现在可以由GPnP来自动实现. GPnP不是一个单独的概念,它依赖于以下特性:在一个XML配置文件 ...
- python的eval、exec函数使用总结
eval函数 一.函数的作用 将字符串str当成有效的表达式来求值并返回计算结果.它要执行的python代码只能是单个运算表达式(不支持任意形式的赋值操作),而不能是复杂的代码逻辑. 二.函数的定义 ...
- Convolutional Neural Networks
卷积神经网络(Convolutional Neural Networks/ CNN/ConvNets) 卷积神经网络和普通神经网络十分相似: 组成它们的神经元都具有可学习的权重(weights)和偏置 ...
- django模板中自动加载static
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join( ...
- Linux查看进程,端口,访问url
# 查看进程# ps -ef|grep python# 终止进程# kill -9 id # 端口 netstat -ntl # 显示正在监听的tcp端口,以端口号显示 netstat -apn|gr ...
- psc格式的文件是什么
psc格式的文件是什么 是navicat 这个工具导出的数据文件 可以使用备份还原功能 提取sql
- VisualSVN: 只能修改自己提交日志
上回讲过怎么修改日志信息,这次想提交怎么只能修改自己提交的. 现在演示用户111来修改libra的日志信息 这个公正的SVN出现了 用户111说小样,不让我改,那我修改自己提交的日志总行了吧!! 我改 ...