暑假集训(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\n",x1,y1,x2,y2);
19     else
20       printf("%.3lf %.3lf %.3lf %.3lf\n",x2,y2,x1,y1);
21   }
22   return 0;
23 }

时间: 2024-08-28 15:44:13

暑假集训(2)第八弹 ----- Points on Cycle(hdu1700)的相关文章

暑假集训(1)第八弹 -----Catch the cow(Poj3984)

Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, }; 它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线. Input 一个5 × 5的二维数组,表示一个迷宫.数据保证有唯一解. Output 左上角到右下角的最短路径,格式如样例所示. Sa

暑假集训(2)第八弹 ----- Hero(hdu4310)

K - Hero Crawling in process... Crawling failed Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description When playing DotA with god-like rivals and pig-like team members, you have to face an embarrassing

暑假集训(4)第八弹——— 组合(hdu1524)

题意概括:你已经赢得两局,最后一局是N个棋子往后移动,最后一个无法移动的玩家失败. 题目分析:有向无环图sg值游戏,尼姆游戏的抽象表达.得到每个棋子的sg值之后,把他们异或起来,考察异或值是否为0. 1 #include "cstdio" 2 int figure[1004][1004]; 3 int sg[1004]; 4 int t; 5 void fbegin() 6 { 7 for (int i=0;i<1004;i++) 8 { 9 sg[i] = -1; 10 for

暑假集训(2)第五弹 ----- Who&#39;s in the Middle(poj2388)

G - Who's in the Middle Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'median

暑假集训(2)第七弹 -----今年暑假不AC(hdu2037)

J - 今年暑假不AC Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description “今年暑假不AC?” “是的.” “那你干什么呢?” “看世界杯呀,笨蛋!” “@#$%^&*%...” 确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电视了. 作为球迷,一定想看尽量

暑假集训(1)第七弹 -----Oil Deposits(Poj1562)

Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It

暑假集训(1)第三弹 -----Dungeon Master(Poj2251)

Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot m

暑假集训(4)第五弹——— 数论(hdu1222)

题意概括:那天以后,你好说歹说,都快炼成三寸不烂之舍之际,小A总算不在摆着死人脸,鼓着死鱼眼.有了点恢复的征兆.可孟子这家伙说的话还是有点道理,那什么天将降....额,总之,由于贤者法阵未完成,而小A又迟迟不现身,FFF团团长连下七道圣火令追杀你们,最先赶到地,机械化部队,它们除了智能不高外,可以说是无懈可击.这正是你要利用的一点,利用他们的行动轨迹,躲藏起来. 问题分析:首先用辗转相除法求得gcd(n,m),若n>m 则gcd(n,m)为一可逃反之,非一可逃. 1 #include "c

暑假集训(1)第六弹 -----简单计算器(Hdoj1237)

Description 读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值. Input 测试输入包含若干测试用例,每个测试用例占一行,每行不超过200个字符,整数和运算符之间用一个空格分隔.没有非法表达式.当一行中只有0时输入结束,相应的结果不要输出. Output 对每个测试用例输出1行,即该表达式的值,精确到小数点后2位. Sample Input 1 + 2 4 + 2 * 5 - 7 / 11 0 Sample Output 3.00 13.36 问题分析:难