Initial knowledge of the structural body

Source: Internet
Author: User

Q: Distance Sort

Total time limit: 1000ms memory limit: 65536kB

Describe

The n points in three-dimensional space (no more than 10) are given, and the distance between N points 22 is calculated, and the coordinates of two points are output from large to small and the distance between them is obtained.

Input

The input consists of two lines, the first line containing an integer n representing the number of points, and the second row contains the coordinates of each point (coordinates are integers). The coordinates of the point range from 0 to 100, and there are no points in the input data that have the same coordinates.

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 from which the distance is reserved to a few 2 bits behind the points.

(method to retain to 2 decimal places 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

Tips

method to retain the 2 digits after the decimal point with the cout output: cout<<fixed<<setprecision (2) <<x

Attention:

The bubbling sort satisfies the following properties, the choice of sorting and quick sorting (qsort or sort) requires additional processing for the following scenarios when using bubbling sorting, be aware of the processing of the boundary conditions, and ensure that the two numbers of comparisons are within the array range.

S

#include <stdio.h> #include <math.h>struct point{int x, Y, z;}; struct dist{struct point a,b;double len; int main () {int n;int i,j;int t=0;struct point a[12];struct Dist b[101],c;scanf ('%d ', &n); for (i=0;i<n;i++) {scanf ( "%d%d%d", &a[i].x,&a[i].y,&a[i].z);} for (i=0;i<n-1;i++) {for (j=i+1;j<n;j++) {b[t]. A=a[i];b[t]. B=a[j];b[t].len=sqrt ((a[i].x-a[j].x) * (a[i].x-a[j].x) +  (a[i].y-a[j].y) * (A[I].Y-A[J].Y) +  (a[i].z-a[j].z) * (A[I].Z-A[J].Z));  t++;}} for (i=0;i<n;i++) {for (j=i;j>=0&&b[j].len<b[j+1].len;j--) {c=b[j];b[j]=b[j+1];b[j+1]=c;}} For (i=0;i<n* (n-1)/2;i++) {printf ("(%d,%d,%d)-(%d,%d,%d) =%.2lf\n", B[i]. A.x,b[i]. A.y,b[i]. A.z,b[i]. B.x,b[i]. B.y,b[i]. B.z,b[i].len);} return 0;}

Initial knowledge of the structural body

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.