3 solutions
-
1
#include<bits/stdc++.h> using namespace std; int q[1000005]; int a,n; int main(){ while(cin>>a>>n){ int c2=1,c3=1,x=1; q[0]=q[1]=a; while(x<n){ if(q[c2]*2+1>q[c3]*3+1){ q[++x]=q[c3++]*3+1; }else if(q[c2]*2+1<q[c3]*3+1){ q[++x]=q[c2++]*2+1; }else{ q[++x]=q[c2]*2+1; c2++,c3++; } } cout<<q[n]<<endl; } return 0; }
转自庄老师,做了一点简化
-
0
//Double Pointer #include<cstdio> #include<algorithm> using namespace std; int blah[1000001]={},a,n; int main() { while(scanf("%d %d",&a,&n)==2) { blah[1]=a; int i=1,p2=1,p3=1; while(i<n) { int t2=blah[p2]*2+1,t3=blah[p3]*3+1; // printf("t2=%d t3=%d\n",t2,t3); if(t2<t3) blah[++i]=t2,p2++; else if(t2>t3) blah[++i]=t3,p3++; else blah[++i]=t3,p2++,p3++; } printf("%d\n",blah[n]); } return 0; }
-
0
#include<bits/stdc++.h> using namespace std; const int N=2e+6; long long ans[N]; int main(){ int a,n; while(cin>>a>>n){ int r=2,_2=1,_3=1; ans[1]=a; while(r<n+1){ long long ta=ans[_2]*2+1,tb=ans[_3]*3+1; long long t=min(ta,tb); if(ta==t) _2++; else _3++; if(t==ans[r-1]) continue; ans[r++]=t; } cout<<ans[n]<<"\n"; } }
- 1
Information
- ID
- 818
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- # Submissions
- 84
- Accepted
- 24
- Uploaded By