杭电多校第八场 Clockwise or Counterclockwise(向量叉乘)

朱浩大
2023-12-01

Problem Description
It is preferrable to read the pdf statment.

After some basic geometric lessons, Cuber QQ has learned that one can draw one and only one circle across three given distinct points, on a 2D plane. Specialized in art, Cuber QQ has shown remarkable skills to draw circle in one stroke, especially when the stroke is done clockwise. He wonder whether he will be able to do that if 3 points has been given.

In particular, he is given three distinct points A(x1,y1), B(x2,y2), C(x3,y3) which lie on a circle centered at O(0,0). Imagine starting from A, he draws the circle across B and finally gets C. Determine whether he is drawing clockwise or counterclockwise.

Input
The first line contains an integer T (1≤T≤1 000), denoting the number of test cases.

In the next T lines, each line contains six space-separated integers x1, y1, x2, y2, x3, y3 (−109≤x1,y1,x2,y2,x3,y3≤109) denoting the coordinate of A, B and C.

It is guaranteed that A, B, C are pairwise distinct and |AO|=|BO|=|CO|>0.

Output
For each test case, output one line containing ‘‘Clockwise’’ or ‘‘Counterclockwise’’.

Sample Input
3
1 2 2 1 -1 -2
4 3 -4 3 3 4
4 -3 4 3 3 4

Sample Output
Clockwise
Clockwise
Counterclockwise

Source
2020 Multi-University Training Contest 8

题意:
A,B,C是圆上三点,求A->B->C是顺时针还是逆时针。

思路:
复习了一下叉乘。
AB向量叉乘AC向量是正数还是负数,如果是正数意味着角度AB转向AC角度小于等于180度,则为逆时针。否则顺时针。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <map>
#include <string>
#include <set>

typedef long long ll;
using namespace std;

const int maxn = 1e5 + 7;

struct Node {
    ll x,y;
}a,b,c;

int main() {
    int T;scanf("%d",&T);
    while(T--) {
        scanf("%lld%lld%lld%lld%lld%lld",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y);
        Node v1 = Node{a.x - b.x,a.y - b.y};
        Node v2 = Node{a.x - c.x,a.y - c.y};
        ll num = v1.x * v2.y - v1.y * v2.x;
        if(num < 0) {
            printf("Clockwise\n");
        } else {
            printf("Counterclockwise\n");
        }
    }
    return 0;
}
 类似资料: