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”.
瞎做的2333
- O点和P3都在P1P2这条有向线段的右侧。
- O在P1P2左侧,P3在右侧。
然后用ToLeft判断一下即可。
#include
#define int long long
using namespace std;
//不开long long见祖宗
struct Point
{
int x, y;
} p[4];
int Area2(Point p, Point q, Point s)
{
return p.x * q.y -p.y * q.x
+ q.x * s.y - q.y * s.x
+s.x * p.y -s.y * p.x;
}
bool ToLeft(Point p, Point q, Point s){ return Area2(p, q, s) > 0;}
signed main()
{
int t;
cin >> t;
while(t--)
{
int x1, y1, x2, y2, x3, y3;
cin >> p[1].x >> p[1].y >> p[2].x >> p[2].y >> p[3].x >> p[3].y;
Point temp = {0, 0};
bool flag1 = ToLeft(p[1], p[2], temp), flag2 = ToLeft(p[2], p[3], temp), flag3 = ToLeft(p[3], p[1], temp), flag4 = ToLeft(p[1], p[2], p[3]);
if(flag1 == 0 && flag4 == 0 || flag1 == 1 && flag4 == 0) cout << "Clockwise" << endl;
else cout << "Counterclockwise" << endl;
}
return 0;
}