Editorial for Inaho IV
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
The solution requires the knowledge of basic geometry. The question is asking for the Euclidean distance between two points in -dimensional space.
First of all, it should be known that the formula for calculating Euclidean distance in -dimensional space is:
For the first subtask, the -dimensional distance formula can be expanded to dimensions.
For the second and last subtasks, the -dimensional distance formula can be expanded to -dimensions.
The formula for calculating Euclidean distance in -dimensional space is
The proof is left as an exercise for the reader.
The second subtask was specifically dedicated to those who used 32-bit floating-point variables instead of 64-bit floating-point variables in their calculations.
Time Complexity:
Sample Solution - D
import std.math;
import std.stdio;
void main()
{
int N;
double distance = 0;
double[1000] a, b;
scanf("%d", &N);
foreach(x;0..N)
scanf("%lf", &a[x]);
foreach(x;0..N)
scanf("%lf", &b[x]);
foreach(x;0..N)
distance += (b[x]-a[x])*(b[x]-a[x]);
printf("%lf\n", sqrt(distance));
}
Comments