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;
    }
     
  • 相关阅读:
    pycharm中以pytest的方式运行测试用例
    jmeter 固定吞吐量控制器 Constant Throughput Timer
    jmeter 循环控制器使用
    jmeter 24个常用函数
    jmeter 参数化取唯一值
    jmeter之json提取器
    【转】Jmeter如何把响应数据的结果保存到本地的一个文件
    jmeter测试并发
    jmeter参数为Excel表格
    jmeter接口调用
  • 原文地址:https://www.cnblogs.com/dshn/p/4750709.html
Copyright © 2011-2022 走看看