博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU1700:Points on Cycle
阅读量:4616 次
发布时间:2019-06-09

本文共 1775 字,大约阅读时间需要 5 分钟。

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
 

 

题意:以原点为圆心,给出圆上的一点,要求两位两点,是的这三个点的距离和最大,很容易想到这是一个等边三角形,而事实上,经过对题目给出样例的测试也证明了这确实是一个等边三角形

思路:几何水题

我们可以得到方程组

x^2+y^2 = r^2

(a-x)^2+(b-y^2)=3r^2

解方程组得到的两点即为三角形的另外两点

 

#include 
#include
int main(){ int t; double x,y,x2,y2,r; double ax,ay,bx,by,k,m,l,A,B,C; scanf("%d",&t); while(t--) { scanf("%lf%lf",&x,&y); r = x*x+y*y; A = r; B = y*r; C = r*r/4-r*x*x; ay = (-B-sqrt(B*B-4*A*C))/(2*A); by = (-B+sqrt(B*B-4*A*C))/(2*A); if(fabs(x-0)<1e-7)//防止除数出现0的情况 { ax=-sqrt(r-ay*ay); bx=sqrt(r-by*by); } else { ax=(-r/2-ay*y)/x;//由于ay必定小于by,所以ax也必定小于bx,所以无需进行大小判定 bx=(-r/2-by*y)/x; } printf("%.3lf %.3lf %.3lf %.3lf\n",ax,ay,bx,by); } return 0;}

转载于:https://www.cnblogs.com/pangblog/p/3260274.html

你可能感兴趣的文章
android Javah生成JNI头文件
查看>>
npm创建react项目
查看>>
关于u32中查找和定位最后到bit Number of 1 Bits
查看>>
sql数据库查询
查看>>
云计算技能图谱
查看>>
js的块级作用域
查看>>
委托、Lambda表达式和事件
查看>>
typecho模板制作代码收集
查看>>
Python学习笔记4:集合方法
查看>>
elasticsearch的监控脚本
查看>>
你还在为使用P/Invoke时,写不出win32 api对应的C#声明而犯愁吗?
查看>>
msbuild property metadata会overwrite msbuild task中的properties
查看>>
python系列前期笔记
查看>>
Android -- sqlite数据库随apk发布
查看>>
Android -- Fragment
查看>>
前端性能优化和规范
查看>>
《你必须知道的.NET》读书笔记三:体验OO之美
查看>>
python 之进程篇
查看>>
移动Web 开发中的一些前端知识收集汇总
查看>>
框架编程之路一
查看>>