Inside Triangle

题目1 : Inside Triangle

时间限制: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<bits/stdc++.h>
#define LL long long
using namespace std;
LL area(LL x1,LL y1,LL x2,LL y2,LL x3,LL y3)
{
	return abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2));
}

int main()
{
	LL Px, Py, Ax, Ay, Bx, By, Cx, Cy;
	LL S, S1, S2, S3;
	LL t;
	for(cin>>t;t>0;t--)
	{
		cin>>Px>>Py>>Ax>>Ay>>Bx>>By>>Cx>>Cy;
		S  = area(Ax, Ay, Bx, By, Cx, Cy);
		S1 = area(Px, Py, Ax, Ay, Bx, By);
		S2 = area(Px, Py, Ax, Ay, Cx, Cy);
		S3 = area(Px, Py, Bx, By, Cx, Cy);
		if(S1+S2+S3<=S)cout<<"YES\n";else cout<<"NO\n";
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_38970751/article/details/85331031