码迷,mamicode.com
首页 > 其他好文 > 详细

L - Points on Cycle

时间:2016-07-21 17:30:44      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

L - 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
 
//这周做题真的很蛋疼,什么都一次过不了,什么奇奇怪怪的错误都有。
这题用旋转公式,弧度传4*pi/3 ,竟然是错的,必须传-2*pi/3,真是不懂,好烦!!!
 
技术分享
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <math.h>
 4 using namespace std;
 5 
 6 const double pi=3.141592654;
 7 
 8 int main()
 9 {
10     int t;
11     scanf("%d",&t);
12     double x,y;
13     double x1,y1,x2,y2;
14     while (t--)
15     {
16         scanf("%lf%lf",&x,&y);
17         x1=x*cos(2*pi/3)-y*sin(2*pi/3);
18         y1=x*sin(2*pi/3)+y*cos(2*pi/3);
19         x2=x*cos(-2*pi/3)-y*sin(-2*pi/3);
20         y2=x*sin(-2*pi/3)+y*cos(-2*pi/3);
21         if (y1<y2||(y1==y2&&x1<x2))
22         {
23             printf("%.3lf %.3lf %.3lf %.3lf\n",x1,y1,x2,y2);
24         }
25         else
26         {
27             printf("%.3lf %.3lf %.3lf %.3lf\n",x2,y2,x1,y1);
28         }
29     }
30     return 0;
31 }
View Code

 

 
 
 
 
 

L - Points on Cycle

标签:

原文地址:http://www.cnblogs.com/haoabcd2010/p/5692214.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!