1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define a 4
#define b 100
#define c 100
#define d 100
int indice3(int i1,int i2,int i3,int t1,int t2,int t3);
int indice4(int i1,int i2,int i3,int i4,int t1,int t2,int t3,int t4);
int main (void)
{
int i,j,k,*n,*m;
double *x,*y,*z;
int n1x,n1y,n1z,nm;
x=(double *)calloc(a,sizeof(double));
y=(double *)calloc(a,sizeof(double));
z=(double *)calloc(a,sizeof(double));
x[0]=0.1;y[0]=0.1;z[0]=0.1;
x[1]=0.1;y[1]=0.2;z[1]=0.1;
x[2]=0.1;y[2]=0.1;z[2]=0.2;
x[3]=2.2;y[3]=2.2;z[3]=2.2;
n = ( int*)malloc(sizeof*(n)*a*b*c*d);
m = (int*)malloc(sizeof*(m)*b*c*d);
for (i=0;i<b;i++)
for (j=0;j<c;j++)
for (k=0;k<d;k++)
m[indice3(i,j,k,b,c,d)]=0;
for (i=0;i<a;i++)
{
n1x=floor(x[i]);
n1y=floor(y[i]);
n1z=floor(z[i]);
nm=m[indice3(n1x,n1y,n1z,b,c,d)]+1;
m[indice3(n1x,n1y,n1z,b,c,d)]=nm;
n[indice4(nm,n1x,n1y,n1z,a,b,c,d)]=i;
}
free(m);
free(n);
return EXIT_SUCCESS;
}
int indice3(int i1,int i2,int i3,int t1,int t2,int t3)
{
int position;
position = (i1*t2*t3) + (i2*t3) + i3;
return (position);
}
int indice4(int i1,int i2,int i3,int i4,int t1,int t2,int t3,int t4)
{
int position;
position = (i1*t2*t3*t4) + (i2*t3*t4) + (i3*t4) + i4;
return(position);
} |
Partager