nyist 68三點順序

來源:互聯網
上載者:User

標籤:style   http   color   os   io   strong   資料   div   

三點順序時間限制: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 30 1 1 0 0 00 0 0 0 0 0
範例輸出
01














#include<stdio.h>
int main()
{
int x1,y1,x2,y2,x3,y3;
double s;
while(scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3)&& x1+x2+x3+y1+y2+y3)
{
s=x1*y2+x3*y1+x2*y3-x3*y2-x2*y1-x1*y3;//AB和BC向量的叉積......
if(s<0) printf("1\n");
else printf("0\n");


}
return 0;
}

 

 

 

叉積的長度 |a×b| 可以解釋成以a和b為鄰邊的平行四邊形的面積。

 

 

 

 

 

 

 

 

 

#include<stdio.h>
#include<math.h>
main()
{
int x1,x2,x3,y1,y2,y3;
double s;
while(scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3))
{
if(x1==0&&y1==0&&x2==0&&y2==0&&x3==0&&y3==0) break;

s=((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/2.0;
if(s>=0)
printf("0\n");
else
printf("1\n");
}
}

 

 

 

 

 

 

#include<stdio.h>
#include<math.h>
main()
{
int x1,x2,x3,y1,y2,y3;
double s;
while(scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3),( x1||y1 || x2||y2 ||x3||y3 ))
{

s=((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/2.0;
if(s>=0)
printf("0\n");
else
printf("1\n");
}
}

 

 

#include<iostream>
using namespace std;
int main()
{
while(1)
{
int x1,y1,x2,y2,x3,y3;
cin>>x1>>y1>>x2>>y2>>x3>>y3;

if(x1==0&&y1==0&&x2==0&&y2==0&&x3==0&&y3==0) break;

int ax=x2-x1,ay=y2-y1,bx=x2-x3,by=y2-y3;
if(ax*by-ay*bx<0)
cout<<0<<endl;

else
cout<<1<<endl;

}
}

 

 

 

 

 








聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.