codeforce 13B

来源:互联网 发布:人像合成软件下载 编辑:程序博客网 时间:2024/04/30 07:06

http://vjudge.net/contest/view.action?cid=47948#problem/B

Description

Little Petya learns how to write. The teacher gave pupils the task to write the letter A on the sheet of paper. It is required to check whether Petya really had written the letter A.

You are given three segments on the plane. They form the letter A if the following conditions hold:

  • Two segments have common endpoint (lets call these segments first and second), while the third segment connects two points on the different segments.
  • The angle between the first and the second segments is greater than 0 and do not exceed 90 degrees.
  • The third segment divides each of the first two segments in proportion not less than 1 / 4 (i.e. the ratio of the length of the shortest part to the length of the longest part is not less than 1 / 4).

Input

The first line contains one integer t (1 ≤ t ≤ 10000) — the number of test cases to solve. Each case consists of three lines. Each of these three lines contains four space-separated integers — coordinates of the endpoints of one of the segments. All coordinates do not exceed 108 by absolute value. All segments have positive length.

Output

Output one line for each test case. Print «YES» (without quotes), if the segments form the letter A and «NO» otherwise.

Sample Input

Input
34 4 6 04 1 5 24 0 4 40 0 0 60 6 2 -41 1 0 10 0 0 50 5 2 -11 2 0 1
Output
YESNOYES
题目要求判断所给的三条线段是否可以构成一个“A”,(值得注意的是题目给出的第三条边的两个顶点不一定在第一和第二两条线段上)

#include <stdio.h>#include <string.h>#include <iostream>#include <cmath>using namespace std;int fang(int a,int b,int c,int d,int e,int f)//判断是否在三点是否共线{    if((long long)(f-b)*(c-a)==(long long)(d-b)*(e-a))        return 1;    return 0;}int xie(int x,int y,int a,int b,int p,int q)//判断两线段的夹角是否在0~90之间{    if((long long)(a-x)*(p-x)+(long long)(b-y)*(q-y)<0)        return 0;    return 1;}int juli(int x,int y,int m,int n,int a,int b)//判断分割的线段是否长:短<0.25{    if(x!=a)    {        if(a>x)        {            if((a-x)*5<(m-x)) return 0;            if((a-x)*5>(m-x)*4) return 0;            return 1;        }        else        {            if((x-a)*5<(x-m)) return 0;            if((x-a)*5>(x-m)*4) return 0;            return 1;        }    }    else    {        if(b>y)        {            if((b-y)*5<(n-y))return 0;            if((b-y)*5>(n-y)*4)return 0;            return 1;        }        else        {            if((y-b)*5<(y-n))return 0;            if((y-b)*5>(y-n)*4)return 0;            return 1;        }    }}struct note{    int x,y,z,zz;} a[7];int main(){    int t,x,y,m,n,p,q,x1,y1,x2,y2;    int count1,count2;    //int cnt=0;    while(~scanf("%d",&t))    {        while(t--)        {            //cnt++;            for(int i=0; i<3; i++)                scanf("%d%d%d%d",&a[i].x,&a[i].y,&a[i].z,&a[i].zz);                /*if(cnt==11)                {                    for(int i=0;i<3;i++)                       printf("(%d %d %d %d)\n",a[i].x,a[i].y,a[i].z,a[i].zz);                }*/            for(int i=0; i<2; i++)                for(int j=i+1; j<3; j++)                {                    if(a[i].x==a[j].x&&a[i].y==a[j].y)                    {                        x=a[i].x,y=a[i].y;                        m=a[i].z,n=a[i].zz;                        p=a[j].z,q=a[j].zz;                        count1=i;                        count2=j;                    }                    else if(a[i].x==a[j].z&&a[i].y==a[j].zz)                    {                        x=a[i].x,y=a[i].y;                        m=a[i].z,n=a[i].zz;                        p=a[j].x,q=a[j].y;                        count1=i;                        count2=j;                    }                    else if(a[i].z==a[j].z&&a[i].zz==a[j].zz)                    {                        x=a[i].z,y=a[i].zz;                        m=a[i].x,n=a[i].y;                        p=a[j].x,q=a[j].y;                        count1=i;                        count2=j;                    }                    else if(a[i].z==a[j].x&&a[i].zz==a[j].y)                    {                        x=a[i].z,y=a[i].zz;                        m=a[i].x,n=a[i].y;                        p=a[j].z,q=a[j].zz;                        count1=i;                        count2=j;                    }                }            for(int i=0; i<3; i++)                if(i!=count1&&i!=count2)                {                    x1=a[i].x,y1=a[i].y,x2=a[i].z,y2=a[i].zz;                    break;                }            int flag=1;            if(xie(x,y,m,n,p,q)==0)                flag=0;            if(flag)            {                if(fang(x,y,m,n,x1,y1)&&fang(x,y,p,q,x2,y2))                {                    if(juli(x,y,m,n,x1,y1)==0)                        flag=0;                    if(juli(x,y,p,q,x2,y2)==0)                        flag=0;                }                else if(fang(x,y,p,q,x1,y1)&&fang(x,y,m,n,x2,y2))                {                    if(juli(x,y,m,n,x2,y2)==0)                        flag=0;                    if(juli(x,y,p,q,x1,y1)==0)                        flag=0;                }                else                    flag=0;            }            if(flag==1)                printf("YES\n");            else                printf("NO\n");        }    }    return 0;}/*99-28888230 -71114151 -32083310 -73477619-28888230 -71114151 -31657786 -72349471-30485770 -72295885 -29687000 -71705018*/


0 0
原创粉丝点击