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

Re:1046 麻烦了

Posted by xiaoha at 2005-01-11 22:55:28 on Problem 1046
In Reply To:1046 麻烦了 Posted by:90401525 at 2005-01-11 22:37:38
这是正确答案
#include<stdio.h>
void main(){
	int x[100],y[100],z[100],t[100];
	int i,j,a,b,c;
	for(i=1;i<17;i++)
		scanf("%d %d %d",&x[i],&y[i],&z[i]);
	scanf("%d %d %d",&a,&b,&c);
	while(a!=-1&&b!=-1&&c!=-1){
		int n=1;//这地方要先负值,不然的话就有可能
	    for(i=1;i<=16;i++)
	    	t[i]=(a-x[i])*(a-x[i])+(b-y[i])*(b-y[i])+(c-z[i])*(c-z[i]);
        for(i=2;i<=16;i++)
		    if(t[1]>t[i]){
			    j=t[1];
			    t[1]=t[i];
			    t[i]=j;
				n=i;
			}
	    printf("(%d,%d,%d) maps to (%d,%d,%d)\n",a,b,c,x[n],y[n],z[n]);
		scanf("%d %d %d",&a,&b,&c);
	}
}

> #include<stdio.h>
> void main(){
> 	int x[100],y[100],z[100],t[100];
> 	int i,j,a,b,c;
> 	for(i=1;i<17;i++)
> 		scanf("%d %d %d",&x[i],&y[i],&z[i]);
> 	scanf("%d %d %d",&a,&b,&c);
> 	while(a!=-1&&b!=-1&&c!=-1){
> 		int n;
> 	    for(i=1;i<=16;i++)
> 	    	t[i]=(a-x[i])*(a-x[i])+(b-y[i])*(b-y[i])+(c-z[i])*(c-z[i]);
>         for(i=2;i<=16;i++)
> 		    if(t[1]>t[i]){
> 			    j=t[1];
> 			    t[1]=t[i];
> 			    t[i]=j;
> 				n=i;
> 			}
> 	    printf("(%d,%d,%d) maps to (%d,%d,%d)\n",a,b,c,x[n],y[n],z[n]);
> 		scanf("%d %d %d",&a,&b,&c);
> 	}
> }
> 
> 

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