2014年10月2日 星期四

2014/10/2 TopCoder SRM 146 Div1 600 Masterbrain

// http://community.topcoder.com/stat?c=problem_statement&pm=1541&rd=4535
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

struct Masterbrain
{
    int possibleSecrets(vector <string> g, vector <string> r)
    {

        int cnt = 0;

        for(int i = 0; i < 7*7*7*7; i++)
        {
            int err = 0; int A[4];

            for(int vi = 0, vn = g.size(); vi < vn; vi++)
            {
                int _i = i;

                for(int j = 0; j < 4; j++)
                    A[j] = _i%7+1, _i/=7;

                int b = 0, w = 0;

                for(int j = 0; j < 4; j++)
                    if( A[j] == g[vi][j]-'0' ) b++, A[j] = 0;

                for(int j = 0; j < 4; j++)
                {
                    if( A[j] == 0 ) continue;

                    for(int k = 0; k < 4; k++)
                        if( A[k] == g[vi][j]-'0' ){ w++, A[k] = -1; break; }
                }

                if( b == r[vi][0]-'0' && w == r[vi][3]-'0' );
                else err++;
            }

            if( err == 1 ) cnt++;
        }

        return cnt;
    }
};

沒有留言:

張貼留言