天天看點

2020 杭電多校第八場 1003 Clockwise or Counterclockwise 向量叉乘2020 杭電多校第八場 1003 Clockwise or Counterclockwise 向量叉乘

2020 杭電多校第八場 1003 Clockwise or Counterclockwise 向量叉乘

題解

如果點 C 在向量 AB⃗ 的右側, 則方向為順時針, 否則為逆時針.C 在 AB⃗ 的右側, 當且

僅當 AB⃗ × BC < ⃗ 0 .故我們隻需要判斷這兩條向量的叉積的正負性即可。

代碼

#include<stdio.h>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
const int mod = 1e9+7;
const int maxn = 1e6+5;
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int T=1;
    scanf("%d",&T);
    while(T--)
    {
        double x1,y1,x2,y2,x3,y3;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        double ans=(x2-x1)*(y3-y1)-(y2-y1)*(x3-x1);
        if(ans > 0) {
            puts("Counterclockwise");
        }
        else {
            puts("Clockwise");
        }
    }
    return 0;
}
           

繼續閱讀