Mocha and Railgun

 链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网
 

题目描述

There is a candy store near Mocha's school. It's said that the storekeeper, Dagashiya, can cast the railgun spell. To be the most powerful Mahou Shoujo, Mocha asks Dagashiya to teach her the railgun spell.

To test her mastery of this spell, Mocha creates a circular wall CCC whose center is (0,0)(0,0)(0,0). The railgun spell has a base segment ABABAB with length 2d2d2d. When it is cast, a point PPP on the circular wall will be destroyed if and only if it meets the following conditions:
 

  1. The projection of point PPP on line ABABAB lies on the segment ABABAB (inclusive).
  2. A,B,PA,B,PA,B,P make a counterclockwise turn, that is to say AB→×AP→>0\overrightarrow{AB} \times \overrightarrow{AP} > 0AB×AP>0.


Mocha chooses a point QQQ which strictly lies in the circle and sets QQQ as the center of the base segment. Then Mocha will choose an angle α\alphaα arbitrarily and rotate the base segment around QQQ by α\alphaα. Because Mocha is a rookie of the spell, the endpoints of the base segment will always lie in CCC strictly, which means the distance from QQQ to the wall CCC is greater than ddd.

Mocha wants to know the maximum length of the wall that can be destroyed in one cast.

You can see the note for better understanding.

输入描述:

The first line is an integer TTT (1≤T≤1051\leq T\leq 10^51≤T≤105) — the number of test cases.

In each test case, the first line is an integer rrr (1≤r≤1091\leq r\leq 10^91≤r≤109) — the radius of the circular wall CCC.

The next line contains three integers xQ,yQ,dx_Q,y_Q,dxQ​,yQ​,d — the coordinates of the point QQQ and a half of the length of the base segment.

输出描述:

For each test case, print a real number in a single line, denoting the maximum length of the wall that Mocha can destroy in one cast. Your answer will be considered equal to the correct answer when their absolute or relative error doesn't exceed 10−610^{-6}10−6.

示例1

输入

1 2 0 0 1

输出

2.094395102393

题意:圆内给一点q,然后以q为中心,d为长度双向扩展,然后投影圆弧,观察最长的圆弧长度,求值。

思路:通过几何关系求解。

 S边最大时,弧长最大,弦长越长,弧长越大得到,那么 S^2 = a^2 + b^2;

b为定值,求a的最大值。

距离圆心越远的弧长越长

#include<iostream>
#include<cmath>
using namespace std;
#define pi acos(-1)
double len(double x1,double y1,double x2,double y2)
{
     return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        double r,x,y,d;
        cin>>r;
        cin>>x>>y>>d;
        double lenx = len(0,0,x,y); 
        double lend = lenx + d;
        double lenm = lenx - d;
        double sum;
        if(lenx-d>0)
        sum = (acos(lenm/r) - acos(lend/r)) * r;
        else
        sum = (pi-acos((d-lenx)/r)-acos(lend/r))*r; 
        
        printf("%.12f\n",sum);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值