Total time limit: 1000ms memory limit: 65536kB The description gives the n points in the three-dimensional space (no more than 10), the distance between the N-point 22, and the distance between the two points and the distance from large to small.
The input input includes two lines, the first row contains an integer n representing the number of points, and the second row contains the coordinates of each point (the coordinates are all integers). The coordinates of a point are 0 to 100, and there is no point in the input data that coordinates the same. Output for input data of size n, Output n (n-1)/2 line format the following distance information:
(X1,Y1,Z1)-(X2,Y2,Z2) = distance
The distance remains to 2 digits behind the points.
(a method that retains 2 digits after the decimal point with cout output: cout<<fixed<<setprecision (2) <<x) sample input
4 0 0 0 1 0 0 1 1 0 1 1-
1
Sample output
(0,0,0)-(1,1,1) =1.73
(0,0,0)-(1,1,0) =1.41
(1,0,0)-(1,1,1) =1.41 (
0,0,0)-(1,0,0) =1.00 (
1,0,0)-( 1,1,0) =1.00
(1,1,0)-(1,1,1) =1.00
Tip to retain 2 digits after the decimal point with cout output: cout<<fixed<<setprecision (2) <<x
Attention:
Bubble sort satisfies the nature of the following, and selecting sort and quick sort (qsort or sort) requires extra processing of the following
Use bubble sort to pay attention to the handling of boundary conditions, to ensure that the comparison of the two numbers are within the array range
1. For two points (X1,Y1,Z1) and (X2,Y2,Z2) in a row of output, the point (X1,Y1,Z1) should appear in front of the point (X2,Y2,Z2) in the input data.
Like input:
2
0 0 0 1 1 1
The output is:
(0,0,0)-(1,1,1) =1.73
But if you enter:
2
1 1 1 0 0 0
The output should be:
(1,1,1)-(0,0,0) =1.73
2. If the distance between two pairs of points p1,p2 and P3,P4 is the same, the first point pair in the input data is output.
Like input:
3
0 0 0 0 0 1 0 0 2
The output is:
(0,0,0)-(0,0,2) =2.00
(0,0,0)-(0,0,1) =1.00
(0,0,1)-(0,0,2) =1.00
If the input becomes:
3
0 0 2 0 0 1 0 0 0
The output should be:
(0,0,2)-(0,0,0) =2.00
(0,0,2)-(0,0,1) =1.00
(0,0,1)-(0,0,0) =1.00
Call the library function. Lazy again.
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <
assert.h> #include <ctype.h> #include <stdlib.h> #include <math.h> using namespace std; struct point{int x,y,z;}
P[200];
struct ans{int h1,h2;
Double Juli;
}J[10100];
Double CE (point a1,point A2) {return sqrt (a1.x-a2.x) * (a1.x-a2.x) + (A1.Y-A2.Y) * (A1.Y-A2.Y) + (a1.z-a2.z) * (A1.Z-A2.Z));
BOOL CMP (ANS A1,ans A2) {if (A1.juli!=a2.juli) return a1.juli>a2.juli;
else if (A1.H1!=A2.H1) return a1.h1<a2.h1;
else return a1.h2<a2.h2;
int main () {//freopen ("In.txt", "R", stdin);//freopen ("OUT.txt", "w", stdout);
int n;
scanf ("%d", &n);
int i=0;
for (i=0;i<n;i++) {scanf ("%d%d%d", &p[i].x,&p[i].y,&p[i].z);
Int J;
int cnt=0;
for (i=0;i<n;i++) for (j=i+1;j<n;j++) {j[cnt].h1 = i;
J[CNT].H2 = j; J[cnt++].juli = CE (p[i],p[j]);
Sort (j,j+cnt,cmp); for (i=0;i<cnt;i++) {printf (%d,%d,%d)-(%d,%d,%d) =%.2lf\n, P[j[i].h1].x,p[j[i].h1].y,p[j[i].h1].z,
P[j[i].h2].x,p[j[i].h2].y,p[j[i].h2].z,j[i].juli);
return 0; }