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 zzt123 at 2011-12-08 12:20:07 on Problem 1046
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d,e,f,m1,m2=0;
	int i=0;
	int s[48]={0};
	do
	{
		cin>>a>>b>>c;
		if(a<0||a>255||b<0||b>255||c<0||c>255)
			return 0;
		s[3*i]=a;
		s[3*i+1]=b;
		s[3*i+2]=c;
		i++;
	}while(i<16);
    cin>>d>>e>>f;
	while(d>=0&&d<=255&&e>=0&&e<=255&&f>=0&&f<=255&&d!=-1&&e!=-1&&f!=-1)
	{
		m1=(d-s[0])*(d-s[0])+(e-s[1])*(e-s[1])+(f-s[2])*(f-s[2]);
		for(int j=3;j<48;j+=3)
		{
			if(m1>(d-s[j])*(d-s[j])+(e-s[j+1])*(e-s[j+1])+(f-s[j+2])*(f-s[j+2]))
			{
				m2=j;
				m1=(d-s[j])*(d-s[j])+(e-s[j+1])*(e-s[j+1])+(f-s[j+2])*(f-s[j+2]);
			}
		}
		cout<<"("<<d<<","<<e<<","<<f<<") maps to ("<<s[m2]<<","<<s[m2+1]<<","<<s[m2+2]<<")"<<endl;
		cin>>d>>e>>f;
	}
	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