AB 到 BC 右旋 ABxBC<0
AB 到 BC 左旋 ABxBC>0
[ x为叉积 AB=(xb-xa,yb-ya) ]
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <bitset> 14 #include <ext/rope> 15 #include <algorithm> 16 #include <iostream> 17 using namespace std; 18 #define ll long long 19 #define minv 1e-6 20 #define inf 1e9 21 #define pi 3.1415926536 22 #define nl 2.7182818284 23 const ll mod=1e9+7;//998244353 24 const int maxn=1e5+10; 25 26 struct point 27 { 28 ll x,y; 29 }a,b,c; 30 31 ll compare(point u,point v) 32 { 33 return u.x*v.y-v.x*u.y; 34 } 35 36 ll cross(point u,point v,point w) 37 { 38 return compare({v.x-u.x,v.y-u.y},{w.x-v.x,w.y-v.y}); 39 } 40 41 int main() 42 { 43 /** 44 input: 45 A:(xa,ya) 46 B:(xb,yb) 47 C:(xc,yc) 48 49 AB 到 BC 右旋 value<0 50 AB 到 BC 左旋 value>0 51 **/ 52 ll xa,ya,xb,yb,xc,yc,v; 53 scanf("%lld%lld",&xa,&ya); 54 a={xa,ya}; 55 scanf("%lld%lld",&xb,&yb); 56 b={xb,yb}; 57 scanf("%lld%lld",&xc,&yc); 58 c={xc,yc}; 59 60 v=cross(a,b,c); 61 if (v<0) 62 printf("%d",-1); 63 else if (v>0) 64 printf("%d",1); 65 else 66 printf("%d",0); 67 return 0; 68 } 69 /* 70 2 1 71 1 0 72 0 1 73 -1 74 75 2 1 76 1 0 77 0 -2 78 1 79 80 2 1 81 1 0 82 0 -1 83 0 84 85 ------ 86 87 0 1 88 1 0 89 2 1 90 1 91 92 0 -2 93 1 0 94 2 1 95 -1 96 97 0 -1 98 1 0 99 2 1 100 0 101 102 */