现在给你不共线的三个点A,B,C的坐标,它们一定能组成一个三角形,现在让你判断A,B,C是顺时针给出的还是逆时针给出的?
如:
图1:顺时针给出
图2:逆时针给出
<图1> <图2>
0 0 1 1 1 3 0 1 1 0 0 0 0 0 0 0 0 0
0 1
#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;
}
}
原文:http://www.cnblogs.com/2014acm/p/3911243.html