Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一个可以运行的代码供参考,不足之处望指正……

Posted by summery at 2006-04-08 23:27:27 on Problem 1046
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
    int a[16][3];
    int x,y,z;
    double min = 600.0,t;
    int k;
    
    for(int i = 0 ;i<16; i++)
     cin>>a[i][0]>>a[i][1]>>a[i][2];
     
     while(cin>>x>>y>>z)
     {
       if(x==-1&&y==-1&&z==-1)
        break;
        min = 600.0;
        for(int j =0; j<16; j++)
         {
            t =sqrt((a[j][0]-x)*(a[j][0]-x)+(a[j][1]-y)*(a[j][1]-y)+(a[j][2]-z)*(a[j][2]-z));
            if(t<min) 
            {
              min = t;
              k =j;           
            }
         }
         cout<<"("<<x<<","<<y<<","<<z<<") "<<"maps to ("<<a[k][0]<<","<<a[k][1]<<","<<a[k][2]<<")"<<endl;
     }  
     return 0; 
     
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator