链接: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:
- The projection of point PPP on line ABABAB lies on the segment ABABAB (inclusive).
- 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
备注:
转存失败重新上传取消
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;
}