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;
    }
     
  • 相关阅读:
    Redis分布式锁的实现原理
    Redis锁的简单应用
    Redis所需内存 超过可用内存怎么办
    redis学习笔记之虚拟内存
    组织安全性SQL
    应收发票相关脚本
    用户与职责与请求关系语句
    应收事物处理删除 SQL 语句
    总账库存科目明细追溯
    月结各模块关闭情况查询
  • 原文地址:https://www.cnblogs.com/dshn/p/4750709.html
Copyright © 2011-2022 走看看