P1010Help
查看原帖
P1010Help
338370
Merron楼主2020/7/15 11:14

RT

为什么会全TLE? 有优化方法吗?

求大神赐教!

#include <iostream>
#include <string>
#define TEXT string 
using namespace std ;
int n ;

string Go (int x, int i = 0, string s = TEXT (" "))
{
    if (x == 0) return TEXT ("0") ;
    do
    {
        if (x & 1)
        {
            s = (i == 1 ? "2" : "2("+ Go (i) + ")") + 
            (s == "" ? "" : "+") + s ;
        }
    }
    while (i ++ , x >> 1) ;
}

int main ()
{
    cin >> n ;
    cout << Go (n) << endl ;
    return 0 ;
}
2020/7/15 11:14
加载中...