zoukankan      html  css  js  c++  java
  • C

    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 (1T1 000), denoting the number of test cases.

    In the next T lines, each line contains six space-separated integers x1y1x2y2x3y3 (109x1,y1,x2,y2,x3,y3109) denoting the coordinate of AB and C.

    It is guaranteed that ABC 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;
    }
    

      

  • 相关阅读:
    Qt调用外部程序QProcess通信
    QT错误:collect2:ld returned 1 exit status
    ARM编译空间属性(转)
    深入C语言内存区域分配(进程的各个段)详解(转)
    Linux系统的组成和内核的组成
    C语言中,头文件和源文件的关系(转)
    Ubuntu安装samba服务器
    2018年应该做的事
    生活经历1
    学习笔记
  • 原文地址:https://www.cnblogs.com/SutsuharaYuki/p/13520364.html
Copyright © 2011-2022 走看看