https://vjudge.net/contest/389195#problem/C
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.
InputThe 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.OutputFor 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来形成圆,问该圆是逆时针还是顺时针形成。
思路:
求向量
内积>0 为顺时针形成
内积<0 为逆时针形成
(原本还考虑了用参考点的左右相对位置关系来做太麻烦
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<bitset> #include<cassert> #include<cctype> #include<cmath> #include<cstdlib> #include<ctime> #include<deque> #include<iomanip> #include<list> #include<map> #include<queue> #include<set> #include<stack> #include<vector> #include <vector> #include <iterator> #include <utility> #include <sstream> #include <limits> #include <numeric> #include <functional> using namespace std; #define gc getchar() #define mem(a) memset(a,0,sizeof(a)) #define debug(x) cout<<"debug:"<<#x<<" = "<<x<<endl; #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int,int> pii; typedef char ch; typedef double db; const double PI=acos(-1.0); const double eps=1e-6; const int inf=0x3f3f3f3f; const int maxn=1e5+10; const int maxm=2007; //const int maxm=100+10; const int N=1e6+10; const int mod=1e9+7; ll x[4] = {0}; ll y[4] = {0}; ll S(int a , int b , int c) { ll s = x[a]*y[b] - y[a]*x[b] + x[b]*y[c] - y[b]*x[c] + x[c]*y[a] - y[c]*x[a]; return s; } int main() { int T = 0; cin >> T; while(T--) { cin >> x[1] >> y[1] >> x[2] >> y[2] >> x[3] >> y[3]; bool f = S(1,2,3) > 0; if(!f) { cout << "Clockwise" <<endl; } else { cout << "Counterclockwise" << endl; } } return 0; }
今天的文章counterclockwise_counter-clockwise「建议收藏」分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/66565.html