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 ...
随机推荐
- Tornado 框架的使用
Tornado tornado是一个轻量级python的web框架,他是非阻塞式的,而且速度非常快.得利于其 非阻塞的方式和对 epoll 的运用,Tornado 每秒可以处理数以千计的连接,这意味着 ...
- 双向链表-java完全解析
原文:https://blog.csdn.net/nzfxx/article/details/51728516 "双向链表"-数据结构算法-之通俗易懂,完全解析 1.概念的引入 相 ...
- 网络虚拟化中的 offload 技术:LSO/LRO、GSO/GRO、TSO/UFO、RSS、VXLAN
offload offload特性,主要是指将本来在操作系统协议栈中进行的一些数据包处理(如IP分片.TCP分片.重组.checksum校验等)放到网卡硬件中去做,降低系统 CPU 消耗,提高处理的性 ...
- tornado-简单的服务器非阻塞
1.服务器 非阻塞 import tornado.ioloop import tornado.web import tornado.httpserver # 非阻塞 import tornado.op ...
- (10/24) 图片跳坑大战--处理html中的图片
补充,在前面的服务启动执行命令中,我们在package.json中的配置信息为: "scripts": { "server": "webpack-de ...
- Oracle JOB简例
JOB declare jobno number; begin dbms_job.submit( jobno, 'insert into tmptable1 values(1,1);', to_dat ...
- cobller安装操作系统
参考网站:https://blog.csdn.net/admin_root1/article/details/78911718 https://www.cnblogs.com/panwenbin-lo ...
- node 删除文件 和文件夹
删除文件 var fs = require('fs'); fs.unlink(path,callback); 删除文件夹 deleteFolder(path); function deleteFold ...
- 字符串和JSON对象互转的方法
采用Ajax的项目开发过程中,经常需要将JSON格式的字符串返回到前端,前端解析成JS对象(JSON ).字符串转JSON对象 1.eval方式解析.function strToJson(str){ ...
- Delphi 变体数组 Dataset Locate 查找定位
Format 函数 Delphi 支持“开参数”和动态数组,变体数组,使用时的语法类似 Delphi 中的集合:采用两个方括号把不同类型的变量括起来(这太方便了啊),也可以采用声明一个 TVarRec ...