2013省赛集训5 - Triangle

 

Triangle

Time Limit 1000ms

Memory Limit 65536K

description

  Given the coordinates of the vertices of a triangle,And a point. You just need to judge whether the point is in the Triangle.
							

input

  The input contains several test cases. For each test case, only line contains eight integer numbers , describing the coordinates of the triangle and the point. All the integer is in range of [-100  , 100].
  The end of the input is indicated by a line containing eight zeros separated by spaces.
							

output

  For each test case ,if the point is inside of the triangle,please output the string ”YES”,else output the string “NO”. You just need to follow the following examples.
							

sample_input

0 0 4 0 0 4 3 1
0 0 4 0 0 4 1 2
0 0 4 0 0 4 -1 -1
0 0 0 0 0 0 0 0
							

sample_output

NO
YES
NO
							

 

 

 


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>

using namespace std;

int area(int x1,int y1,int x2,int y2,int x3,int y3)
{
    return x1*y2+x2*y3+x3*y1-x2*y1-x3*y2-x1*y3;
}//三角形有向面积的2倍,逆时针正,顺时针负

int main()
{
    int x1,y1,x2,y2,x3,y3,x,y,s1,s2,s3,s;
    while(scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3,&x,&y)!=EOF)
    {
        if(x1==0&&y1==0&&x2==0&&y2==0&&x3==0&&y3==0&&x==0&&y==0)
            break;
        x1+=100;y1+=100;x2+=100;y2+=100;x3+=100;y3+=100;x+=100;y+=100;
        s1=abs(area(x1,y1,x2,y2,x,y));
        s2=abs(area(x1,y1,x3,y3,x,y));
        s3=abs(area(x2,y2,x3,y3,x,y));
        s=abs(area(x1,y1,x2,y2,x3,y3));
        if((s1+s2+s3)==s&&s1&&s2&&s3)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值