Untitled

unknown
plain_text
18 days ago
2.4 kB
4
Indexable
Never
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=2e5+5,mod=1000000000+7;
long double const PI = acos(-1);
long double const eps = 1e-7;
ll di[] = {-1 , 0 , 1 , 0 , 1 , -1 , 1 , -1};
ll dj[] = {0 ,1 , 0 , -1 , 1 ,-1 , -1 , 1};
ll MOD=1e9+7;
long double Distance2(long double x1,long double y1,long double x2,long double y2){
long double abs_x= x1-x2;
abs_x*=abs_x;
long double abs_y= y1-y2;
abs_y*=abs_y;
return abs_x+abs_y;
}
bool inbetween(long double angle1, long double angle2, long double angle)
{
if(angle1 > angle2) angle2 += 360 - angle1, angle += 360 - angle1 ,angle1 = 0;
while(angle + eps > 360) angle -= 360;
angle = fmod(angle + 360,360);
return angle + eps > angle1 && angle - eps< angle2;
}

void solve() {
ll r,a,b,tx,ty;
cin>>r>>a>>b>>tx>>ty;
cout<<fixed<<setprecision(7);
if(tx*tx+ty*ty < r*r) return void(cout << sqrt(Distance2(0,0,tx,ty)));
long double x1=r*cos(a*PI/180);
long double y1=r*sin(a*PI/180);
long double x2=r*cos(b*PI/180);
long double y2=r*sin(b*PI/180);
long double angle= atan2(ty,tx)*180/PI;
if(inbetween(a,b,angle)) cout<< sqrt(Distance2(0,0,tx,ty));
else{
long double len = sqrt(Distance2(0,0,tx,ty) - r*r), l = sqrt(Distance2(0,0,tx,ty));
long double angleOffset = atan(len/(r + l)) * 360/PI;
long double angle1 = fmod(angle - angleOffset + 360, 360);
long double angle2 = fmod(angle + angleOffset + 360, 360);
if(inbetween(angle1,angle2,a) && inbetween(angle1,angle2,b)) cout << sqrt(min(Distance2(x1,y1,tx,ty),Distance2(x2,y2,tx,ty))) + r;
else if(inbetween(angle1,angle2,a)) cout << sqrt(Distance2(x1,y1,tx,ty)) + r;
else if(inbetween(angle1,angle2,b)) cout << sqrt(Distance2(x2,y2,tx,ty)) + r;
else
{
long double ans1 =  min({fabs(a - angle1),fabs(b - angle1),fabs(a - angle2),fabs(b - angle2)})*r * PI/180 + len + r;
long double ans2 = (360 - max({fabs(a - angle1),fabs(b - angle1),fabs(a - angle2),fabs(b - angle2)}))*r * PI/180 + len + r;
cout << min(ans1,ans2);
}
}
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(0);
freopen("walls.in", "r", stdin);
int T=1;
cin>>T;
while(T--){
solve();
cout<<endl;
}

}