zoukankan      html  css  js  c++  java
  • Points on cycle

    Description

    There is a cycle with its center on the origin.
    Now give you a point on the cycle, you are to find out the other two points on it, to maximize the sum of the distance between each other
    you may assume that the radius of the cycle will not exceed 1000.
     

    Input

    There are T test cases, in each case there are 2 decimal number representing the coordinate of the given point.
     

    Output

    For each testcase you are supposed to output the coordinates of both of the unknow points by 3 decimal places of precision
    Alway output the lower one first(with a smaller Y-coordinate value), if they have the same Y value output the one with a smaller X.

    NOTE
    when output, if the absolute difference between the coordinate values X1 and X2 is smaller than 0.0005, we assume they are equal.
     

    Sample Input

    2 1.500 2.000 563.585 1.251
     

    Sample Output

    0.982 -2.299 -2.482 0.299 -280.709 -488.704 -282.876 487.453
     
     
    题目大意:
         给出圆上一点求出该园上任选两点使任意该三角形周长。
     
    解题思路:
          最长明显为正三角形周长最长,这题可以用向量旋转公式做,也可以用普通的数学式做。以下给出用向量旋转解题的方法。
     
    代码如下:
    #include<cmath>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    
    const double PI = acos(-1.0);
    struct Point
    {
         double x, y;
    
         Point(double x = 0, double y = 0): x(x), y(y){}
    
         void scan()
         {         scanf("%lf%lf", &x, &y);
         }
    
        void print()
        {
             printf("%.3lf %.3lf", x, y);
         }
    
         bool operator < (const Point &other){
             return y < other.y || (y == other.y && x < other.x);
         }
     };
    
     typedef Point Vector;
    
     Vector rotate(Vector A, double rad)//向量旋转公式
    { return Vector(A.x * cos(rad) - A.y * sin(rad), A.y * cos(rad) + A.x * sin(rad)); } int main() { int t; Point p[3]; scanf("%d", &t); while(t--) { p[0].scan(); p[1] = rotate(p[0], PI * 2 / 3);//逆时针旋转120度 p[2] = rotate(p[0], -PI * 2 / 3);//顺时针旋转120度 if(p[2] < p[1]) swap(p[1], p[2]); p[1].print(); putchar(' '); p[2].print(); putchar(' '); } return 0; }

      

  • 相关阅读:
    使用Myeclipse + SVN + TaoCode 免费实现项目版本控制的详细教程
    国内的代码托管服务
    国内可用的SVN和Git代码托管网站汇总
    需求调研与分析流程
    如何做好新项目的需求调研?(一)
    如何进行有效的需求调研
    weblogic和tomcat
    同步变量也是变量
    并发编程的三个管理
    机器学习
  • 原文地址:https://www.cnblogs.com/llfj/p/5701451.html
Copyright © 2011-2022 走看看