void _pow(int a,int b){
    while(b){
        if(b%2&1) { 
			ans*a;b--;
			ans=ans*pow(pos(a,b/2),2);
		}
        else ans=ans*pow(pos(a,b/2),2);
    }
}
改后——>


void _pow(int a,int b){
    ans=1;
    while(b){
        if(b%2&1) { ans*=a;b--;}
        else { b/=2;a*=a;}
    }
}

二:(hdu1032)为了记忆话递归溢出:

void _find(int v){
    if(v==1) {
         dp[v]=0;
         return ;
    }
    if(v&1) { 
        v=3*v+1;
        _find(v);
        if((v-1)/3<1000010)  dp[(v-1)/3]=dp[v]+1;
    }
    else { 
        v/=2;
        _find(v);
        if(v*2<1000010) dp[v*2]=dp[v]+1;
    }
}

----->改后,虽然没有记忆话,但是至少没有溢出:

void _find(int v){
    int count=1;
    int t=v;
    while(v!=1){
        if(v&1) v=3*v+1;    
        else  v/=2;
        count++;
    }
    dp[t]=count;
}



相关文章:

  • 2022-12-23
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-02
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
  • 2021-04-25
  • 2022-12-23
相关资源
相似解决方案