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;
}
给你一个点在半径为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;
}
相关文章推荐
- hdu1700 Points on Cycle (数学)
- HDU 5533 Dancing Stars on Me(数学+水题)
- hdu 3668 Volume 数学
- hdu - 2058 The sum problem (数学题)
- 【数学 对数】HDU 1141 Factstone Benchmark
- HDU-1060 Leftmost Digit (数学)
- hdu 5065 数学题
- HDU 6033(数学)
- HDU 3398 String 组合数学+N!质因数分解 卡特兰数
- hdu 1597 数学题 find the nth digit
- HDU 1570 A C (数学题)
- HDU - 5974 A Simple Math Problem(ICPC2016 大连现场,简单的数学推理)
- hdu 1700 poj 2954
- hdu_5858_Hard problem(数学题)
- (数学)HDU 6033 Add More Zero
- hdu 1017 A Mathematical Curiosity(数学:水题)
- HDU 4627 The Unsolvable Problem 数学
- HDU 2601:An easy problem【数学】
- HDU 2298 Toxophily(二分+数学)
- HDU 6127 Hard challenge(数学)