[2007年NOIP普及组] Hanoi双塔问题
作者:互联网
分析:根据样例可得x(n)=2+2*2……
运用高精乘进行乘
#include<bits/stdc++.h>
using namespace std;
int c[600000],jw[600000];
int i,n,a[600000],j,b[600000]={0,2},bj;
int main(){
cin>>n;
a[1]=2;
bj=1;
j=1;
for(i=2;i<=n;i++){
for(int ijj=1;ijj<=j;ijj++){
a[ijj]=a[ijj]*2;
a[ijj]=a[ijj]+jw[ijj];
jw[ijj]=0;
if(a[ijj]>=10){
jw[ijj+1]=a[ijj]/10;
a[ijj]=a[ijj]%10;
}
if(ijj==j&&jw[ijj+1]>0){
jw[j+1]=0;
a[j]++;
j++;
break;
}
}
for(int ijj=1;ijj<=j;ijj++){
b[ijj]=b[ijj]+a[ijj];
if(b[ijj]>=10){
b[ijj+1]=b[ijj]/10+b[ijj+1];
b[ijj]=b[ijj]%10;
if(ijj==j) {
j++;
break;
}
}
}
}
for(int ij=j;ij>=1;ij--){
cout<<b[ij];
}
}
标签:10,NOIP,int,jw,Hanoi,ij,600000,2007,ijj 来源: https://www.cnblogs.com/wangjunlong9948/p/16589381.html