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

测试数据全部正确,为什么还是WA了,麻烦高手指点

Posted by acm_primer2007 at 2007-10-05 17:36:13 on Problem 1046
#include <iostream>
#include <cmath>
using namespace std;

struct color {
	int R;
	int G;
	int B;
};

double D(color cl1,color cl2)
{
	double d = (cl1.R-cl2.R)*(cl1.R-cl2.R) + (cl1.G-cl2.G)*(cl1.G-cl2.G) + (cl1.B-cl2.B)*(cl1.B-cl2.B);
	return sqrt(d);
}

void main()
{
	color clr[16];
	for(int i=0;i<16;i++)
	{
		cin>>clr[i].R>>clr[i].G>>clr[i].B;
	}
	

	color test;
	cin>>test.R>>test.G>>test.B;

	while(test.R != -1){

		int minMark=0;
		
		double min = D(clr[0],test);
		
		for(i=1;i<16;i++)
		{
			if( D(clr[i],test) <= min ) {

				min = D(clr[i],test);
				minMark = i;
			}
			
		}
		
		cout<<"("<<test.R<<","<<test.G<<","<<test.B<<")"<<" maps to ("
			<<clr[minMark].R<<","<<clr[minMark].G<<","<<clr[minMark].B<<")"<<endl;
		
		cin>>test.R>>test.G>>test.B;
	
	}

	
}

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