2013省赛集训5 - Triangle

来源:互联网 发布:泛微协同软件 编辑:程序博客网 时间:2024/06/05 19:48

 

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 10 0 4 0 0 4 1 20 0 4 0 0 4 -1 -10 0 0 0 0 0 0 0

sample_output

NOYESNO

 

 

 


#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;}


 

原创粉丝点击