Problem Statement :
You all probably know how to calculate the distance between
two points in two dimensional cartesian plane. But in this problem you have to
find the minimum arc distance between two points and they are on a circle
centered at another point.
You will be given the co-ordinates of the points A
and B and co-ordinate of the center O. You just have to calculate
the minimum arc distance between A and B. In the picture, you
have to calculate the length of arc ACB. You can assume that A and
B will always be on the circle centered at O.
Solution Code :
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
int i,test;
int Ox,Oy,Ax,Ay,Bx,By;
double AB,OB,result,alpha;
cin>>test;
for(i=1;i<=test;i++)
{
cin>>Ox>>Oy>>Ax>>Ay>>Bx>>By;
AB = (Ax-Bx)*(Ax-Bx)+(Ay-By)*(Ay-By);
AB = sqrt(AB);
OB = (Ox-Bx)*(Ox-Bx)+(Oy-By)*(Oy-By);
OB = sqrt(OB);
result = 2*OB*OB - AB*AB;
result = result/(2*OB*OB);
alpha = acos (result ) ;
result = alpha * OB ;
printf("Case %d: %lf\n",i,result);
}
return 0;
}
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
int i,test;
int Ox,Oy,Ax,Ay,Bx,By;
double AB,OB,result,alpha;
cin>>test;
for(i=1;i<=test;i++)
{
cin>>Ox>>Oy>>Ax>>Ay>>Bx>>By;
AB = (Ax-Bx)*(Ax-Bx)+(Ay-By)*(Ay-By);
AB = sqrt(AB);
OB = (Ox-Bx)*(Ox-Bx)+(Oy-By)*(Oy-By);
OB = sqrt(OB);
result = 2*OB*OB - AB*AB;
result = result/(2*OB*OB);
alpha = acos (result ) ;
result = alpha * OB ;
printf("Case %d: %lf\n",i,result);
}
return 0;
}
ভাইয়া আপনার লজিক টা ঠিক ধরতে পারলাম না । এটা কি সূত্র দিয়ে করলেন ?? আর একটা কথা এই প্রব্লেম কি S = 2*pi*r * (angle/360) diye kora somvob ???
উত্তরমুছুনS = r * theta
মুছুনS = minimum arc distance
r = radius of circle
theta = alpha in code
According to cosine rule, cosC = (a^2 + b^2 - c^2)/2ab . Here a==b , as radius of same circle. So we can write cosC = (2*a^2 - c^2)/2ab . The s=r*theta [Here theta is C (variable alpha)]
উত্তরমুছুন