多校第八场——1003 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

题意:
给出三个点A,B,C做一个圆,问从A->B->C是顺时针还是逆时针。

思路:
叉积的一个非常重要性质是可以通过它的符号判断两矢量相互之间的顺逆时针关系:
若 P × Q > 0 , 则P在Q的顺时针方向。
若 P × Q < 0 , 则P在Q的逆时针方向。
若 P × Q = 0 , 则P与Q共线,但可能同向也可能反向

代码:

#include<bits/stdc++.h>
using namespace std;

struct Point
{
	double x;
	double y;
} p1, p2, p3;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin >> T;
	while (T--)
	{
		cin >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
		double temp1 = p2.x - p1.x;
		double temp2 = p2.y - p1.y;
		double temp3 = p3.x - p1.x;
		double temp4 = p3.y - p1.y;
		double temp = temp1 * temp4 - temp2 * temp3;
		if (temp < 0)
		{
			cout << "Clockwise" << endl;
		}
		else
		{
			cout << "Counterclockwise" << endl;
		}
	}
}

 类似资料: