Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
第25题了,路过,贴下代码。#include "iostream" #define MAX 10000 using namespace std; struct node { int a; int b; int c; }s[MAX]; int main(int argc, char* argv[]) { node Q; int top=-1,m,i,p,n; long r,t; while(1) { cin>>Q.a>>Q.b>>Q.c; if(Q.a==-1&&Q.b==-1&&Q.c==-1) break; top++; s[top]=Q; } i=16; for(m=i;m<=top;m++) { r=32767;p=0; for(n=0;n<16;n++) { t=(s[m].a-s[n].a)*(s[m].a-s[n].a)+(s[m].b-s[n].b)*(s[m].b-s[n].b)+(s[m].c-s[n].c)*(s[m].c-s[n].c); if(t<r) { r=t; p=n; } } cout<<'('<<s[m].a<<','<<s[m].b<<','<<s[m].c<<')'<<' '<<"maps"<<' '<<"to"<<' '; cout<<'('<<s[p].a<<','<<s[p].b<<','<<s[p].c<<')'<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator