Project Euler #155: Counting Capacitor Circuits.

Sort by

recency

|

18 Discussions

|

  • + 1 comment

    Hi,

    My code works only for the Test Case 0,1,2,3.

    My output is:

    D(1) = 1, D(2) = 3, D(3) = 7, D(4) = 15, D(5) = 31, D(6) = 63, D(7) = 127, D(8) = 255, D(9) = 511, D(10) = 1023, D(11) = 2047, D(12) = 4095, D(13) = 8191, D(14) = 16383, D(15) = 32767, D(16) = 65535, D(17) = 131071, D(18) = 262143

    In this comment (https://www.hackerrank.com/contests/projecteuler/challenges/euler155/forum/comments/194581) says the required output is: 1, 3, 7, 15, 35, 77, 179, 429, 1039, 2525, 6235, 15463, 38513, 96231, 241519, 607339, 1529533, 3857447.

    My ouput is lower, I dont have duplicate values.

    What is the mistake in my code:

    int main(){
        int n;
        cin >> n;
    
        double C = 60;
        set<double> sGlobal;
        vector< set<double> > vSetValues;
    
        vSetValues.push_back(set<double>());
        vSetValues[0].insert(C);
        sGlobal.insert(C);
    
    //for(n = 1; n < 19; n++){
        for(int i = 1; i < n; i++)
        {
            vSetValues.push_back(set<double>());
    
            for(set<double>::iterator ite = vSetValues[i-1].begin(); ite != vSetValues[i-1].end(); ite++)
            {
                double serie, parallel;
                serie = *ite + C;
                parallel = 1/(1/(*ite) + 1/C);
    
                vSetValues[i].insert(serie);
                vSetValues[i].insert(parallel);
                sGlobal.insert(serie);
                sGlobal.insert(parallel);
            }
        }
    
        //cout << "D(" << n << ") = ";
        cout << sGlobal.size() <<endl;
    //}
    
        return 0;
    }
    
  • + 0 comments

    Here'are the times on my laptop, C++ 16 0m0.304s 17 0m0.768s 18 0m2.104s 1.83s on Hackerrank 19 0m5.868s 20 0m18.168s 21 0m53.888s

    The case n=22 almost killed my 8GB laptop with a swap.

    So, the problem is solvable (at least in c++) without cheating.

  • + 2 comments

    i think there are same difficult point in this problem 1) how to exclude the duplicate value 2) how to get the corrent arrangement of full n capacitors 3) how to speed up(cut some useless branch)

    i have fixed the 1 and 2, but 3 is still a difficult Challenge

  • + 0 comments

    i have noticed that some of possible unique configurations of the capacitor mesh result in duplicate capacitor values.

  • + 1 comment

    i used the property that nC0 + nC1 +......+ nCn = 2^n - 1 but I only got 4 test cases passed. please help.