Mocha and Railgun(几何规律)

链接:https://ac.nowcoder.com/acm/contest/33186/D
来源:牛客网
 

题目描述

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

1
2
0 0 1

输出

复制2.094395102393

2.094395102393

备注:

 

uploading.4e448015.gif

转存失败重新上传取消

In the picture above, the blue lines are the boundaries of the railgun spell. The red arc is the wall being destroyed.

Mocha and Railgun

返回全部题目

列表加载中...

思路:

因为AB可以逆时针旋转,并且假设p的左端点为y1,右端点为y2   弦长=》圆心角=》弧长,=》弦长=sqrt((y1-y2)*(y1-y2)+4*d*d)=》沿OQ方向时,y1-y2最大,(坐标系不是关键,圆心和关系才是)

代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;cin>>t;
    while(t--){
        int r;cin>>r;
        int x,y,d;
        cin>>x>>y>>d;
        double a=r*r*1.0-(sqrt(x*x+y*y)*1.0+d)*(sqrt(x*x+y*y)*1.0+d);
        double b=r*r*1.0-(sqrt(x*x+y*y)*1.0-d)*(sqrt(x*x+y*y)*1.0-d);
        double k=sqrt((sqrt(a)-sqrt(b))*(sqrt(a)-sqrt(b))+4*d*d);
        cout<<fixed<<setprecision(12)<<1.0*2*r*asin(k/r/2.0)<<'\n';
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值