CodeForces 618A Slime Combining
水题,先都合成2,看看有没有1多的,有的话存起来,再把那些2合成3,看看有没有多的2,有的话再存起来。。。一直这样下去
#include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<algorithm> using namespace std; int n; vector<int>ans; int main() { scanf("%d",&n); ans.clear(); int nowNum=1; int nowSum=n; while(1) { if(nowSum%2==1) ans.push_back(nowNum); if(nowSum==1) break; nowSum=nowSum/2; nowNum++; } for(int i=ans.size()-1;i>=0;i--) printf("%d ",ans[i]); printf("\n"); return 0; }