Tuesday, July 29, 2014

TCHS SRM 45 Level one - 250 pt - Solving Equation solution

TCHS SRM 45 Level one - 250 pt - Solving Equation statement: http://community.topcoder.com/stat?c=problem_statement&pm=8141&rd=10799

TCHS SRM 45 Level one - 250 pt - Solving Equation editorial: http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm45

TCHS SRM 45 Level one - 250 pt - Solving Equation solution: 


#include <iostream>
#include <climits>

class SolvingEquation{
    public: int solve(int a, int b, int c, int w) {
        int mi=INT_MAX, flag=0;
        for(int i=0; i<=100; ++i) for(int j=0; j<=100; ++j) for(int k=0; k<=100; ++k) {
            if(a*i + b*j + c*k == w && i+j+k<mi) mi=i+j+k, flag=1; 
        }
        if(flag==1) return mi;
        else return -1;
    }
};

No comments:

Post a Comment