【ACM】三点顺序

 

三点顺序

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
 
描述

现在给你不共线的三个点A,B,C的坐标,它们一定能组成一个三角形,现在让你判断A,B,C是顺时针给出的还是逆时针给出的?

如:

图1:顺时针给出

图2:逆时针给出 

 

        

 

 

       <图1>                   <图2>

 
输入
每行是一组测试数据,有6个整数x1,y1,x2,y2,x3,y3分别表示A,B,C三个点的横纵坐标。(坐标值都在0到10000之间)
输入0 0 0 0 0 0表示输入结束
测试数据不超过10000组
输出
如果这三个点是顺时针给出的,请输出1,逆时针给出则输出0
样例输入
0 0 1 1 1 3
0 1 1 0 0 0
0 0 0 0 0 0
样例输出
0
1


 
#include <iostream>
#include <cstdio>

using namespace std;

int main(){

    int x1,y1,x2,y2,x3,y3;

    while (scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF)
    {
        if (x1==0 && x2==0 && x3==0 && y1==0 && y2==0 && y3==0)
        {
            break;
        }
        int a1 = x2-x1;        //B-A
        int a2 = y2-y1;
        int b1 = x3-x2;        //C-B
        int b2 = y3-y2;
        int c1 = x3-x1;        //C-A
        int c2 = y3-y1;

        
        if (a1==0 || a2==0)        //横或者竖
        {
            if (a1==0)        //
            {
                if (a2>0)        //
                {
                    if (b1>0)        //
                    {
                        cout<<"1"<<endl;
                    }
                    else        //
                    {
                        cout<<"0"<<endl;
                    }
                }
                else        //
                {
                    if (b1>0)        //
                    {
                        cout<<"0"<<endl;
                    }
                    else        //
                    {
                        cout<<"1"<<endl;
                    }
                }
            }
            else            //
            {
                if (a1<0)        //
                {
                    if (b2>0)        //
                    {
                        cout<<"1"<<endl;
                    }
                    else        //
                    {
                        cout<<"0"<<endl;
                    }
                }
                else            //
                {
                    if (b2>0)        //
                    {
                        cout<<"0"<<endl;
                    }
                    else        //
                    {
                        cout<<"1"<<endl;
                    }
                }
            }
        }
        else
        {
            double k = 1.0*a2/a1;
            double temp = y3 - k*(x3-x1) - y1;
            if (a1>0 && a2>0)        //第一象限  不包括边界
            {
                if (temp>0)
                {
                    cout<<"0"<<endl;
                }
                else
                {
                    cout<<"1"<<endl;
                }
            }
            if (a1<0 && a2>0)        //第二象限  不包括边界
            {
                if (temp>0)
                {
                    cout<<"1"<<endl;
                }
                else
                {
                    cout<<"0"<<endl;
                }
            }
            if (a1<0 && a2<0)        //第三象限  不包括边界
            {
                if (temp>0)
                {
                    cout<<"1"<<endl;
                }
                else
                {
                    cout<<"0"<<endl;
                }
            }
            if (a1>0 && a2<0)        //第四象限  不包括边界
            {
                if (temp>0)
                {
                    cout<<"0"<<endl;
                }
                else
                {
                    cout<<"1"<<endl;
                }
            }
        }

    }

    return 0;
}        

 

posted @ 2018-10-28 11:40  凌雨尘  阅读(237)  评论(0编辑  收藏  举报