zoukankan      html  css  js  c++  java
  • hdu1700 Points on Cycle

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=1700

    题目:

    Points on Cycle

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


    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

     思路:

      直接猜是等边三角形,然后发现确实是。

      求其他两个点,直接旋转就行了。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 #include <algorithm>
     5 
     6 
     7 using namespace std;
     8 const double PI = acos(-1.0);
     9 const double eps = 5e-4;
    10 
    11 /****************常用函数***************/
    12 //判断ta与tb的大小关系
    13 int sgn( double ta, double tb)
    14 {
    15     if(fabs(ta-tb)<eps)return 0;
    16     if(ta<tb)   return -1;
    17     return 1;
    18 }
    19 
    20 //
    21 class Point
    22 {
    23 public:
    24 
    25     double x, y;
    26 
    27     Point(){}
    28     Point( double tx, double ty){ x = tx, y = ty;}
    29 
    30 };
    31 //两点间距离
    32 double getdis(const Point &st,const Point &se)
    33 {
    34     return sqrt((st.x - se.x) * (st.x - se.x) + (st.y - se.y) * (st.y - se.y));
    35 }
    36 
    37 int main(void)
    38 {
    39     //freopen("in.acm","r",stdin);
    40     int t;
    41     scanf("%d",&t);
    42     Point pa,pb,pc,pp=Point(0,0);
    43     while(t--)
    44     {
    45         scanf("%lf%lf",&pa.x,&pa.y);
    46         double r = getdis(pa,pp);
    47         double ag = atan2(pa.y,pa.x);
    48         pb.x = r * cos(ag + PI * 2 / 3), pb.y = r * sin(ag + PI * 2 / 3);
    49         pc.x = r * cos(ag - PI * 2 / 3), pc.y = r * sin(ag - PI * 2 / 3);
    50         if(sgn(pb.y,pc.y)>0||(sgn(pb.y,pc.y)==0&&sgn(pb.x,pc.x)>0))
    51             swap(pb,pc);
    52         printf("%.3f %.3f %.3f %.3f
    ",pb.x,pb.y,pc.x,pc.y);
    53     }
    54     return 0;
    55 }
  • 相关阅读:
    pandas 数据类型研究(三)数据类型object与category
    kaggle比赛实践M5-baseline研读
    pd.melt详解--列转行
    kaggle比赛实践M5-数据集介绍
    kaggle比赛实践M5-比赛介绍
    txNLP 335-374
    信息,熵,联合熵,条件熵,互信息(信息增益),交叉熵,相对熵(KL散度)
    框架SpringMVC笔记系列 二 传值
    项目总结笔记系列 Social Hub KT Session1
    读书笔记系列之java性能优化权威指南 一 第一章
  • 原文地址:https://www.cnblogs.com/weeping/p/7656195.html
Copyright © 2011-2022 走看看