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 wd0711672 at 2004-12-20 17:43:31 on Problem 1046
#include<stdio.h>
#include<stdlib.h>
struct position{ int R;int G;int B;int W;}point[1000];
int i,j,k,m,n,p,q;
void main(){
	for(i=0;i<1000;i++){
		scanf("%d%d%d",&point[i].R,&point[i].G,&point[i].B);q=i;
		if(point[i].R==-1&&point[i].G==-1&&point[i].B==-1)  break;}
	for(j=16;j<q;j++){
		for(k=0;k<15;k++){
			m=(point[j].R-point[k].R)*(point[j].R-point[k].R)
				+(point[j].G-point[k].G)*(point[j].G-point[k].G)
				+(point[j].B-point[k].B)*(point[j].B-point[k].B);
            n=(point[j].R-point[k+1].R)*(point[j].R-point[k+1].R)
				+(point[j].G-point[k+1].G)*(point[j].G-point[k+1].G)
				+(point[j].B-point[k+1].B)*(point[j].B-point[k+1].B);
			if(m>n) m=n;}
         for(k=0;k<16;k++){
			p=(point[j].R-point[k].R)*(point[j].R-point[k].R)
				+(point[j].G-point[k].G)*(point[j].G-point[k].G)
				+(point[j].B-point[k].B)*(point[j].B-point[k].B);
			if(p==m)  point[j].W=k;}
    }
     for(j=16;j<q;j++){
		 printf("\n(%d,%d,%d) maps to (%d,%d,%d)",point[j].R,point[j].G,
			 point[j].B,point[point[j].W].R,point[point[j].W].G,
             point[point[j].W].B);}   system("PAUSE");
}

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