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
ACM ICPC 2018 World Finals

这道题唯一的乐趣......

Posted by sunl449554866 at 2014-08-27 17:54:06 on Problem 1046
In Reply To:有硕士博士吗,同等学力的也进来帮帮我,为什么VC能通过提交总是wrong anwser Posted by:winter_1 at 2006-04-23 22:22:27
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

class RGB{
public:
       RGB(const float r,const float g, const float b):
           R(r),G(g),B(b){};
       float R;
       float G;
       float B;
};

istream& operator>>( istream& is, RGB &t){
         is >> t.R >> t.G >> t.B;
         return is;
}

double Distance( const RGB &a, const RGB &b){
       return sqrt( (a.R-b.R)*(a.R-b.R) +
        (a.G-b.G)*(a.G-b.G) + (a.B-b.B)*(a.B-b.B) );
}

int main()
{
    double distance, tem;
    int ans;
    vector<RGB> target(17,RGB(0,0,0));
    for (int i = 1; i <= 16; ++i){
         cin >> target[i];
    } 
    RGB ins(0,0,0);
    while (cin >> ins, ins.R != -1){
           distance = Distance( ins, target[1]);
           ans = 1;
           for (int i = 2; i <= 16; ++i){
                tem = Distance( ins, target[i]);
                if (distance > tem){
                    distance = tem;
                    ans = i;
                }
           }
           cout << "("<<ins.R<<","<<ins.G<<","<<ins.B<<")"
                << " maps to "
                << "("<<target[ans].R<<","<<target[ans].G<<","<<target[ans].B<<")"
                << endl;
    }
    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