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;
    }
    
  • 相关阅读:
    201706120024 编译原理第一次作业
    P2014 选课 题解(树形DP)
    基础算法·二分答案
    P4285 [SHOI2008]汉诺塔 题解 (乱搞)
    2018.12-2019.1 TO-DO LIST
    记录一枚蒟蒻的成长(持续更新)
    P3796 【模板】AC自动机(加强版) 题解(Aho-Corasick Automation)
    BuaacodingT651 我知道你不知道圣诞节做什么 题解(逻辑)
    P2766 最长不下降子序列问题 题解(网络流)
    P2516 [HAOI2010]最长公共子序列 题解(LCS)
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/13497680.html
Copyright © 2011-2022 走看看