ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

C - Clockwise or Counterclockwise

2020-08-17 22:02:40  阅读:251  来源: 互联网

标签:Clockwise const int ll Counterclockwise circle include he


https://vjudge.net/contest/389195#problem/C

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.

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;
}

  

标签:Clockwise,const,int,ll,Counterclockwise,circle,include,he
来源: https://www.cnblogs.com/SutsuharaYuki/p/13520364.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有