Problem Solving

[Topcoder] SRM404 ~ 405 연습

끄적끄적 2008. 10. 20. 11:18
SRM404 DIV2
: 오랜만에 topcoder를 해서 그런가 20분이나 걸렸다.. 꾸준히 연습을 해야겠음.
그냥 string을 sorting해서 eis인지 확인해도 된다.

class ReadingBooks
{
public:

    int countBooks(vector <string> r)
    {   
        int ret = 0;
        int n = r.size();
        for(int i=2; i< n; i++)
        {
            string s = r[i-2].substr(0,1) + r[i-1].substr(0,1) + r[i].substr(0, 1);
            if( count(ALL(s), 'i') == 1 && count(ALL(s), 's') == 1 && count(ALL(s), 'e') == 1)
            {
                i += 2;
                ret++;
            }
        }
        return ret;
    }   
};

SRM405 DIV2

class FallingFactorialPower
{
public:

    double compute(int n, int k)
    {   
        double ret = 1;   
        if( k > 0)
        {
            REP(i, k)
                ret *= (n - i);
        }
        else if( k < 0)
        {
            k = -k;
            REP(i, k)
                ret = ret / ( n+1+i);
        }
       
        return ret;
    }   
};

반응형