HDU1700Points on Cycle(圆心半径)
2015-08-22 17:40
323 查看
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
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
There are T test cases, in each case there are 2 decimal number representing the coordinate of the given point.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
2 1.500 2.000 563.585 1.251
[align=left]Sample Output[/align]
0.982 -2.299 -2.482 0.299 -280.709 -488.704 -282.876 487.453
[align=left]Source[/align]
2007省赛集训队练习赛(1)
[align=left]Recommend[/align]
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\n",ax,ay,bx,by); } return 0; }
相关文章推荐
- TC TCO2015R2D(BalancedSubstrings-天平平衡)
- jQuery学习笔记(三)
- Linux中管理员必知的命令
- 零零碎碎写的脚本(五)显示磁盘信息脚本
- 9 Palindrome Number
- 深入理解Android卷III 第3章 深入理解AudioService (节选)
- 静态构造函数实际运行多少次?
- webstorm 注册码
- 2015-8-20作业
- Problem 2177 ytaaa制造炸药
- 以太网的几种标准
- UI基础:UICollectionView
- HDU1086You can Solve a Geometry Problem too (斜率问题)
- lvs与haproxy
- poj 1459 Power Network
- HDU-5391-Zball in Tina Town
- Codeforces Round #267 (Div. 2)467C George and Job(dp)
- 我的Android开源项目:体重档案
- 数组排序(插入、选择、希尔、堆、归并、快速、冒泡)
- HX711数据格式分析