2020杭电多校第八场—Clockwise or Counterclockwise(几何)
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 <bits/stdc++.h>
#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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!