Lightoj-1433-minimum ARC Distance (geometry)

Source: Internet
Author: User

1433-minimum ARC Distance
PDF (中文版) statisticsforum
Time Limit:2 second (s) Memory limit:32 MB
All probably know how to calculate the distance between both points in and dimensional Cartesian plane. Problem you have to find the minimum arc distance between the points and they is on a circle centered at Anot Her point.

You'll be given the co-ordinates of the points A and B and co-ordinate of the center O. You just has to calculate the minimum arc distance between A and B. In the picture, you had to calculate the length of the arc ACB. You can assume that A and B would always be on the circle centered at O.

Input
Input starts with an integer T (≤100), denoting the number of test cases.

Each case starts with a line containing six integers ox, Oy, Ax, Ay, Bx, by where (Ox, Oy) indicates the co-ordinate of O, (Ax, Ay) denote the co-ordinate of A and (Bx, by) denote the co-ordinate of B. All the integers would lie in the range [1, 10000].

Output
For each case, print the case number and the minimum arc distance. Errors less than 10-3 'll be ignored.

Sample Input
Output for Sample Input
5
5711 3044 477 2186 3257 7746
3233 31 3336 1489 1775 134
453 4480 1137 6678 2395 5716
8757 2995 4807 8660 2294 5429
4439 4272 1366 8741 6820 9145
Case 1:6641.81699183
Case 2:2295.9288
Case 3:1616.690325
Case 4:4155.6415934
Case 5:5732.01250253

#include <iostream>#include<cstdio>#include<cmath>#include<algorithm>using namespacestd;Const DoublePI =3.1415926535898;DoubleDistDoubleX1,DoubleY1,DoubleX2,Doubley2) {    returnsqrt (Pow (x1-x2,2) +pow (Y1-y2,2));}intMain () {intT; DoubleOx,oy,ax,ay,bx,by,a,b,c,arc; scanf ("%d",&T);  for(intt=1; t<=t;t++) {scanf ("%LF%LF%LF%LF%LF%LF",&ox,&oy,&ax,&ay,&bx,&y); A=Dist (Ox,oy,ax,ay); C=Dist (ax,ay,bx,by); Arc= ACOs ((a*a*2-C*C)/(2*a*a)); printf ("Case %d:%.3lf\n", t,a*arc); }        return 0;} 

Lightoj-1433-minimum ARC Distance (geometry)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.