101
Two-Point distance
Time Limit: 3000 MS | memory limit: 65535 KB
Difficulty: 1
Description
Enter two coordinates (x1, Y1), (X2, Y2) (0 <= x1, x2, Y1, Y2 <= 1000), and calculate and output the distance between two points.
Input
Enter an integer N (0 <n <= 1000) In the first line, indicating that N groups of test data exist;
Each group occupies one row and consists of four real numbers, representing X1, Y1, X2, and Y2 respectively. Data is separated by spaces.
Output
For each group of input data, a row is output, and the result is retained with two decimal places.
Sample Input
2
0 0 0 1
0 1 1 0 sample output
1.00
1.41
# Include <math. h>
# Include <stdio. h>
Main ()
{Int N;
Float a, B, c, d;
Double S;
Scanf ("% d \ n", & N );
While (n --)
{
Scanf ("% F", & A, & B, & C, & D );
S = SQRT (a-c) * (a-c) + (B-d) * (B-d ));
Printf ("%. 2f \ n", S );
}
}
# Include <stdio. h>
# Include <math. h>
Int main ()
{
Int N;
Scanf ("% d", & N );
While (n --)
{
Float X1, Y1, X2, Y2,;
Scanf ("% F", & X1, & Y1, & X2, & Y2 );
A = SQRT (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2 ));
Printf ("%. 2f \ n", );
}
Return 0;
}
# Include <stdio. h>
# Include <iostream>
# Include <math. h>
Using namespace STD;
Int main ()
{
Int N;
Double D, X1, Y1, X2, Y2;
Cin> N;
While (n --)
{
Cin> x1> Y1> X2> Y2;
D = SQRT (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2 ));
Printf ("%. 2f \ n", d );
}
Return 0;
}
# Include <stdio. h>
# Include <math. h>
Int main ()
{
Int N, I;
Float x1, x2, Y1, Y2, M, K;
Scanf ("% d", & N );
For (I = 0; I <n; I ++)
{
Scanf ("% F", & X1, & Y1, & X2, & Y2 ); // scanf ("% F \ n", & X1, & Y1, & X2, & Y2); Error
M = (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2 ));
K = SQRT (m );
Printf ("%. 2f \ n", k );
}
Return 0;
}
# Include <iostream>
# Include <iomanip>
# Include <math. h>
Using namespace STD;
Int main ()
{
Int N;
Double M, J, X1, Y1, X2, Y2;
Cin> N;
While (n --)
{
Cin> x1> Y1> X2> Y2;
M = (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2 );
J = SQRT (m );
Cout. SETF (IOs: fixed );
Cout <setprecision (2) <j <Endl;
}
Return 0;
}
# Include <iostream>
# Include <iomanip>
# Include <cmath>
Using namespace STD;
Int main ()
{
Int N;
Double x1, x2, Y1, Y2;
Cin> N;
While (n --)
{
Cin> x1> Y1> X2> Y2;
Cout <setprecision (2) <setiosflags (IOs: fixed) <SQRT (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2) <Endl;
}
Return 0;
}
# Include <iostream>
# Include <cmath>
# Include <iomanip>
Using namespace STD;
Int main ()
{
Int m;
Cin> m;
While (M --)
{
Double X1, Y1, X2, Y2;
Cin> x1> Y1> X2> Y2;
Cout <fixed <setprecision (2) <SQRT (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2) <Endl;
}
Return 0;
}
# Include <stdio. h>
# Include <math. h>
# Include <iostream>
Using namespace STD;
Int main ()
{
Double round, X1, Y1, X2, Y2, DIS;
Cin> round;
While (round --)
{
Cin> x1> Y1> X2> Y2;
Dis = SQRT (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2 ));
Printf ("%. 2f \ n", DIS );
}
Return 0;
}
# Include <stdio. h>
# Include <math. h>
Float fun (float X1, float X2, float Y1, float Y2 ){
Float S1, S2, S3;
S1 = (x1-x2) * (x1-x2 );
S2 = (y1-y2) * (y1-y2 );
S3 = SQRT (S1 + S2 );
Return S3;
}
Int main (){
Float x1, x2, Y1, Y2;
Int N;
Float m;
Scanf ("% d", & N );
While (n --){
Scanf ("% F", & X1, & X2, & Y1, & Y2 );
M = fun (x1, x2, Y1, Y2 );
Printf ("%. 2f \ n", M );
}
Return 0;
}
*********************************
# Include <iostream>
# Include <cmath>
# Include <iomanip>
Using namespace STD;
Double Power (Double X)
{
Double F = 1.0;
F = x * X;
Return (f );
}
Int main ()
{
Double Power (Double X );
Double X [2], Y [2], N;
Int m, I;
Cin> m;
While (M --)
{
Cin> X [0]> Y [0]> X [1]> Y [1];
N = 0.0;
I = n = SQRT (Power (X [0]-y [0]) + power (X [1]-y [1]);
If (n = I)
Cout <n <". 00" <Endl;
Else
Cout <setprecision (3) <n <Endl;
}
Return 0;
}
************************************
# Include <stdio. h>
# Include <math. h>
Int main (void)
{
Double N, X1, Y1, X2, Y2, ans;
Scanf ("% d", & N );
While (n --)
{
Scanf ("% d", & X1, & Y1, & X2, & Y2 );
Ans = SQRT (POW (FABS (x1-x2), 2) + POW (FABS (y1-y2), 2 ));
Printf ("%. 2f \ n", ANS );
}
Return 0;
}
# Include <iostream>
# Include <cmath>
# Include <iomanip>
Using namespace STD;
Int main ()
{
Double N, a [4], E, B, d;
Cin> N;
While (n --)
{
For (INT I = 0; I <4; I ++)
Cin> A [I];
E = (a [0]-A [2]) * (a [0]-A [2]);
B = (a [1]-A [3]) * (a [1]-A [3]);
D = SQRT (E + B );
Cout <setiosflags (IOs: fixed) <setprecision (2) <D <Endl;
}
Return 0;
} // Have you learned C ++?
# Include <stdio. h>
# Include <math. h>
Int main ()
{
Int N, I;
Float a [100], B [100], x1, x2, Y1, Y2;
Scanf ("% d \ n", & N );
For (I = 0; I <n; I ++)
{Scanf ("% F", & X1, & Y1, & X2, & Y2 );
A [I] = SQRT (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2 ));
}
For (I = 0; I <n; I ++) printf ("%. 2f \ n", a [I]);
}
# Include <stdio. h>
# Include <math. h>
Main ()
{
Int X1 [1000] = {0}, X2 [1000] = {0}, Y1 [1000] = {0}, Y2 [1000] = {0}, n, t, I;
Float s [1000] = {0 };
Scanf ("% d", & N );
For (I = 0; I <n; I ++)
Scanf ("% d", & X1 [I], & Y1 [I], & X2 [I], & Y2 [I]);
For (I = 0; I <n; I ++)
{
T = x2 [I] * X2 [I]-X1 [I] * X1 [I] + y2 [I] * Y2 [I]-Y1 [I] * Y1 [I ];
S [I] = SQRT (t );
}
For (I = 0; I <n; I ++)
Printf ("%. 2f \ n", s [I]);
Return 0;
}
**************************************** **************************************** *********************************** 888
1284
Input and Output 5 (mathematical functions)
Time limit (Common/Java): 1000 ms/3000 Ms running memory limit: 65536 Kbyte
Total submissions: 810 pass the test: 536
Description
The coordinates (double type) of the two points on the input plane are used to calculate the distance between the two points.
Input
Coordinates of two points (four real numbers ).
Output
The distance between two points (retain three decimal places ).
Sample Input
10.5 1.6 3.5 4.8
Sample output
7.697
# Include <stdio. h>
# Include <math. h>
Main ()
{Double A, B, C, D;
Scanf ("% lf", & A, & B, & C, & D );
Printf ("%. 3lf \ n", SQRT (a-c) * (a-c) + (B-d) * (B-d )));
}
# Include <stdio. h>
# Include <math. h>
Main ()
{
Float a, B, c, d, S, T;
Scanf ("% F", & A, & B, & C, & D );
S = (a-c) * (a-c) + (B-d) * (B-d );
T = SQRT (s );
Printf ("%. 3f", t );
}
# Include <stdio. h>
# Include <math. h>
Int main ()
{
Double X, Y, M, N, D;
Scanf ("% lf", & X, & Y );
Scanf ("% lf", & M, & N );
D = SQRT (X-m) * (X-m) + (Y-N) * (Y-N ));
Printf ("%. 3lf \ n", d );
}
# Include <iostream>
# Include <cmath>
# Include <iomanip>
Using namespace STD;
Int main (INT argc, char * argv [])
{
Double x1, x2, Y1, Y2;
Cin> x1> Y1> X2> Y2;
Cout <fixed <setprecision (3 );
Cout <SQRT (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2) <Endl;
Return 0;
}
# Include <math. h>
# Include <stdio. h>
Void main ()
{
Float a, B, c, d;
Double S;
Scanf ("% F", & A, & B, & C, & D );
S = SQRT (a-c) * (a-c) + (B-d) * (B-d ));
Printf ("%. 3f \ n", S );
}