您的位置:首页 > 其它

HDU 1700 数学题

2013-07-03 10:30 218 查看
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1700

给你一个点在半径为r的圆上,该圆圆心在原点上,让你求圆上两个点是这两个点与给出这个点的距离最大

显然是互为120度的时候最大。

首先可以求出圆的半径,然后用两个公式求解方程组

a*b=|a|*|b|*cos(120);

x*x+y*y=r*r;

解出方程刚好有两个解,及为所求。

代码如下:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std;

typedef long long LL;
const int N=21;
const LL II=1000000007;

double x,y,r,r2;
double xx0,yy0,xx1,yy1;

int main()
{
int T;
cin>>T;
while(T--)
{
scanf("%lf%lf",&x,&y);
r2=(x*x+y*y);
double a,b,c;
a=r2;
b=r2*y;
c=r2*r2/4-x*x*r2;
yy0=(-b-sqrt(b*b-4*a*c))/2/a;
yy1=(-b+sqrt(b*b-4*a*c))/2/a;
/*/这个地方求解x不能用x*x+y*y=r2来算,应为不知道正负号
xx0=sqrt(r2-yy0*yy0);
xx1=sqrt(r2-yy1*yy1);*/
if(fabs(x-0)<1e-7)
{
xx0=-sqrt(r2-yy0*yy0);
xx1=sqrt(r2-yy1*yy1);
}
else
{
xx0=(-r2/2-yy0*y)/x;
xx1=(-r2/2-yy1*y)/x;
}
printf("%.3lf %.3lf %.3lf %.3lf\n",xx0,yy0,xx1,yy1);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: