Tuesday, July 1, 2014

TopCoder High School SRM 32 Level one - 250 pt - Boulder Race solution

TopCoder High School SRM 32 Level one - 250 pt - Boulder Race statement: http://community.topcoder.com/stat?c=problem_statement&pm=7237&rd=10656

TopCoder High School SRM 32 Level one - 250 pt - Boulder Race editorial: http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm32

TopCoder High School SRM 32 Level one - 250 pt - Boulder Race solution: 

#include <iostream>
#include <vector>
#include <map>
#include <climits>
using namespace std;

class BoulderRace {
    public: int winner(vector <string> b, int d) {
        int a, mi=INT_MAX, cnt, idx=0;
        map <int, int> c;
        for(int i=0; i<b.size(); i++) {
            a=0;
            cnt=0;
            while(a<d) {
                for(int j=0; j<b[i].length(); j++) {
                    a+=b[i][j]-48;
                    if(a>=d) {
                        if(j+b[i].length()*cnt<mi) mi=j+b[i].length()*cnt, idx=i;
                        break;
                    }
                }
                cnt++;
            }
        }
        return idx;
    }
};

No comments:

Post a Comment