HDU 1700 数学题

题目地址: 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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值