zoukankan      html  css  js  c++  java
  • HDU1700Points on Cycle(圆心半径)

     Points on Cycle

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1897    Accepted Submission(s): 688


    Problem 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
     

    Source
     

    Recommend
    lcy
    思路:已知点(x,y),设所求点为(ax,ay),(bx,by),半径r
    满足(1)  x^2+y^2=r^2;(2)(x-ax)^2+(y-ay)^2=3 r^2
    l联立两式得
    (3)  -2 ax x^2=r^2+2 ay y
    将(1)式带入(3)中得
    4 ay^2+4 y ay+r^2-4 x^2 =0
    解得ay有两个值即为ay,by
     ay = (((-4*y)-sqrt(4*y*4*y-16*(r-4*x*x)))/8);
      by = (((-4*y)+sqrt(4*y*4*y-16*(r-4*x*x)))/8);
     
    #include <stdio.h>
    #include <math.h>
     
    int main()
    {
        int t;
        double x,y,x2,y2,r;
        double ax,ay,bx,by;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%lf%lf",&x,&y);
             r = x*x+y*y;
            ay = (((-4*y)-sqrt(4*y*4*y-16*(r-4*x*x)))/8);
            by = (((-4*y)+sqrt(4*y*4*y-16*(r-4*x*x)))/8);
            if(x==0)
            {
                ax=-sqrt(r-ay*ay);    //一定为负数,只有在x=0的时候可这样计算
                bx=sqrt(r-by*by);
            }
            else
            {
                ax=(-r/2-ay*y)/x;   有(3)式得
                bx=(-r/2-by*y)/x;
            }
            printf("%.3lf %.3lf %.3lf %.3lf
    ",ax,ay,bx,by);
        }
        return 0;
    }
     
  • 相关阅读:
    线性回归与梯度下降法[二]——优化与比较
    matlab基础教程——根据Andrew Ng的machine learning整理
    dapper-dot-net用法及其扩展系列
    线性回归与梯度下降法[一]——原理与实现
    浅析 if __name__ == "__main__":
    Python中集合数据类型之间的'交'、'差'、'并'、'补'的表达方式
    Python中 'is' 跟 '==' 的区别
    Python中的逻辑运算符:'and'与'or'的用法
    Python2跟Python3的区别
    编程语言分类及区别
  • 原文地址:https://www.cnblogs.com/dshn/p/4750709.html
Copyright © 2011-2022 走看看