zoukankan      html  css  js  c++  java
  • 暑假集训(2)第九弹 ----- Points on Cycle(hdu1700)

                                                Points on Cycle

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

    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
         

    问题分析:它是一道几何题,假设以知点a坐标为(x0,y0),位置点b,c为(x1,y1),(x2,y2).  圆方程为x2+y2 = r2;可将圆方程化为x=rcosα,y=rsinα;

    又有x12+y1 2= r2 = x02+y0 2,(a*b)/|a|*|b| = cos120

    易得 acosα + bsinα = -0.5r

           (acosα)2   = (0.5r + bsinα)2

            r2sinα2 + rbsinα + 0.25r2 - a2 = 0

          得   x1 = -0.5*b + a*√3 * 0.5  或 x1 = -0.5*b - a*√3 *0.5(舍去)

          及   y = -0.5*b - a*√3 * 0.5  或 y= 0.5*b + a*√3 * 0.5(舍去)

    同理可得x2,y2

    也可直接利用cos(α+β) = cosαcosβ - sinαsinβ ,sin(α+β) = sinαcosβ + cosαsinβ求解,

     1 #include <cstdio>
     2 #include <cmath>
     3 int main()
     4 {
     5   double a,b,x0,y0,x1,y1,x2,y2;
     6   int t;
     7   a=sqrt(3.0)/2;
     8   b=-0.5;
     9   scanf("%d",&t);
    10    while(t--)
    11   {
    12     scanf("%lf%lf",&x0,&y0);
    13     x1 = b*x0 - a*y0;
    14     y1 = b*y0 + a*x0;
    15     x2 = b*x0 + a*y0;
    16     y2 = b*y0 - a*x0;
    17     if(y1<y2 || ((fabs(y1-y2) < 0.005) && x1 < x2))
    18       printf("%.3lf %.3lf %.3lf %.3lf
    ",x1,y1,x2,y2);
    19     else
    20       printf("%.3lf %.3lf %.3lf %.3lf
    ",x2,y2,x1,y1);
    21   }
    22   return 0;
    23 }
    View Code

     

     

     

     
  • 相关阅读:
    Qt QString判断是否是数字
    Qt 判断QString中的字符串是否为纯数字
    Qt delete和deletelater的区别
    Qt QTcpSocket waitForReadyRead()等函数用法——客户端开关读写应用笔记
    Notepad++对比两个文件不同的方法
    Qt error C1071 :在注释中遇到意外的文件结束
    Qt error C2601: “...”: 本地函数定义是非法的
    Qt 错误 C1071 在注释中遇到意外的文件结束 的解决办法
    Qt 串口和线程的简单结合(通过子线程操作串口、movetothread)
    Qt 实现多线程的串口通信
  • 原文地址:https://www.cnblogs.com/huas-zlw/p/5692757.html
Copyright © 2011-2022 走看看