[ create a new paste ] login | about

Link: http://codepad.org/Xsktf8lp    [ raw code | output | fork ]

C++, pasted on Jun 13:
#include <iostream>
using namespace std;

class Solution{
public:
   int nextTPH(int &t, int &p, int &h)
   {    
        h++;
        int Hex = 0;
        for (;;h++)
        {
            int Hex = h * ( 2 * h - 1);
            
            double dt = (-1 + sqrt(1 + 8 * Hex))/2;
            t = (int)dt;
            double dp = (1 + sqrt(1 + 24 * Hex))/6;
            p = (int)dp;
            
            
            if (dt - t < 1.e-6 && t - dt < 1.e-6 && dp - p < 1.e-6 && p - dp < 1.e-6 ) return Hex;
        }
        return Hex;
   }
};

int main(){
    Solution test;

    int t = 285;
    int p = 165;
    int h = 143;
    
    cout << test.nextTPH(t, p, h) <<endl;
    return 0;
}


Output:
1
Timeout


Create a new paste based on this one


Comments: