Drifting is a driving style in which the driver uses the throttle, brakes, clutch, gear shifting and steering input to keep the car in a state of oversteer while manoeuvring from turn to turn. As a sport, the drifting was first practised in Japan in the late 80s before gaining worldwide popularity in the decade that followed.
Keiichi Tsuchiya is a Japanese driver who is better known as the Drift King. He played an important role in popularizing the art of drifting. This pioneer inspired many successful drivers. He appeared in the movie The Fast and the Furious: Tokyo Drift and he is often employed on various movie sets as both driver and stunt coordinator. Keiichi Tsuchiya's talent in the drifting is especially true of his big stunt, the ultimate drifting.
Here is what he could do. The drift car he drives is shaped like a rectangular box of width aa inches and of length bb inches. He makes a right turn of a curve whose internal boundary is an arc with dd degrees in a circle with a radius of rr inches. As a super-skilled driver, he maintains his car to keep the contact and tangency at the internal boundary. That is, the right front corner of the car should always run along the internal boundary and the direction of the car body should always be tangential to the internal boundary.
We have measured that the straightaways before and after the curve are long enough, and the width of the lane is invariable. As what we meet in real life, if a lane has a fixed width, for each point of its one side, the distance to the nearest point of the other side is exactly its width. Now you are asked to calculate the minimal width ww of the lane so that the Drift King could drive throughout the curve without drifting out of the lane.
Input
The input contains several test cases, and the first line contains a positive integer TT indicating the number of test cases which is up to 104104.
For each test case, the only one line contains four integers aa, bb, rr and dd, where 0<a,b,r<1000<a,b,r<100 and 0<d<1800<d<180.
Output
For each test case, output a line containing the minimal width (in inches) of the lane with an absolute or relative error of at most 10−610−6. Precisely speaking, assuming that your answer is aa and the jury's answer is bb, your answer will be considered correct if |a−b|max{1,|b|}≤10−6|a−b|max{1,|b|}≤10−6.
分析:当车完全进入轨道的时候,最小半径就是sqrt((a+r)^2+b^2)。
当车没有完全进入轨道的时候就漂移完了,有弯道角度<内轨道半径和车形成的三角形的角度,此时算一下长度即可。
#include<bits/stdc++.h>
namespace fastIO {
#define BUF_SIZE 100000
bool IOerror = 0;inline char nc() { static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;if (p1 == pend) { p1 = buf;pend = buf + fread(buf, 1, BUF_SIZE, stdin);if (pend == p1) { IOerror = 1;return -1; }}return *p1++; }
inline bool blank(char ch) { return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'; }
inline void read(int &x) {char ch;while (blank(ch = nc()));if (IOerror) return;for (x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0'); }
inline void Out(int a) { if (a < 0) { putchar('-');a = -a; }if (a >= 10) { Out(a / 10); }putchar(a % 10 + '0'); }
#undef BUF_SIZE
};
using namespace fastIO;
using namespace std;
const double pi= acos(-1.0);
int main() {
double a,b,d,r;
int t;
cin>>t;
while(t--)
{
cin>>a>>b>>r>>d;
double len=sqrt(b*b+(a+r)*(a+r));
double jiao=acos((a+r)/len);
d=d/180*pi;
if(d>jiao||fabs(d-jiao)<1e-6){
printf("%.12f\n",len-r);
}
else
{
double len2=(a+r)/cos(d);
double x=len2*sin(d);
x=b-x;
x=sin(d)*x;
printf("%.12f\n",len2+x-r);
}
}
}