69,371
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>#include <iostream>
using namespace std;
class point{
public:
int x;
int y;
int z;
point();
};
point::point()
{
x=0;
y=0;
z=0;
}
int main ()
{
point sixteen[16];
for(int i=0;i<16;++i){
cin>>sixteen[i].x>>sixteen[i].y>>sixteen[i].z;
}
point temp;
while(cin>>temp.x&&temp.x!=-1){
cin>>temp.y>>temp.z;
int flag=-1;
int d=99999;
for(int i=0;i<16;++i){
int a=temp.x-sixteen[i].x;
int b=temp.y-sixteen[i].y;
int c=temp.z-sixteen[i].z;
if(d>a*a+b*b+c*c){
d=a*a+b*b+c*c;
flag=i;
}
}
cout<<"("<<temp.x<<","<<temp.y<<","<<temp.z<<") maps to ("<<sixteen[flag].x<<","<<sixteen[flag].y<<","<<sixteen[flag].z<<")"<<endl;
}
return 0;
}
#include <iostream>
using namespace std;
class point{
public:
int x;
int y;
int z;
point();
};
point::point()
{
x=0;
y=0;
z=0;
}
int main ()
{
point sixteen[16];
for(int i=0;i<16;++i){
cin>>sixteen[i].x>>sixteen[i].y>>sixteen[i].z;
}
point temp;
while(cin>>temp.x&&temp.x!=-1){
cin>>temp.y>>temp.z;
int flag=-1;
int d=99999;
for(int i=0;i<16;++i){
int a=temp.x-sixteen[i].x;
int b=temp.y-sixteen[i].y;
int c=temp.z-sixteen[i].z;
if(d>a*a+b*b+c*c){
d=a*a+b*b+c*c;
flag=i;
}
}
cout<<"("<<temp.x<<","<<temp.y<<","<<temp.z<<") maps to ("<<sixteen[flag].x<<","<<sixteen[flag].y<<","<<sixteen[flag].z<<")"<<endl;
}
return 0;
}
#include<stdio.h>
void main()
{
long a[17][17],i,j,n,r,g,b,m,x,y,z;
for(i=0;i<16;i++)
scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
while(scanf("%d%d%d",&r,&g,&b)&&r>=0&&g>=0&&b>=0)
{
n=9999999;
for(i=0;i<16;i++)
{ m=(r-a[i][0])*(r-a[i][0])+(g-a[i][1])*(g-a[i][1])+(b-a[i][2])*(b-a[i][2]);
if(m<n)
{n=m;x=a[i][0];y=a[i][1];z=a[i][2];}
}
printf("(%d,%d,%d) maps to (%d,%d,%d)\n",r,g,b,x,y,z);
}
}