zoukankan      html  css  js  c++  java
  • 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

    可以看到顺时针分为如图两种情况:
    avatar

    1. O点和P3都在P1P2这条有向线段的右侧。
    2. 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;
    }
    
  • 相关阅读:
    Sigma Function 数学 因子求和
    luogu P3800 Power收集
    LibreOJ #110. 乘法逆元
    luogu P3802 小魔女帕琪
    LibreOJ #6000. 「网络流 24 题」搭配飞行员
    LibreOJ #103. 子串查找
    LibreOJ #102. 最小费用流
    LibreOJ #109. 并查集
    BZOJ 1922: [Sdoi2010]大陆争霸
    LibreOJ #119. 最短路
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/13497680.html
Copyright © 2011-2022 走看看