魔幻国王代码: A(t) = n ; A(t) = A(t-1)*2+1 或者 A(t) = A(t-1) *2 +2, 倒推法,每次计算A(t)能不能被2整除,能,那么上一次肯定用的机器2,不能,上次用的机器1。t=t-1, 依次类推。(感觉跟走台阶是一个类型问题,一共有n个台阶,每次可以走一步或者两步,共有多少走法) #include <iostream> #include <vector> #include <string> #include <iterator> using namespace std; int main(){     vector<int> A;     int i;     cin >> i;          int x = i;     int t = x % 2;          while(x>0){         if(t==0){             A.push_back(2);             x = (x-2)/2;             t = x % 2;         }         else{             A.push_back(1);             x = (x -1) /2;             t = x % 2;         }     }     for(int i= A.size()-1; i>=0;--i){         cout << A[i];     }     return 0;      }
点赞 评论

相关推荐

深夜书店vv:腾讯是这样的,去年很多走廊都加桌子当工区
点赞 评论 收藏
分享
完美的潜伏者许愿简历通过:我上表jd,请求封我做后端大将军的事,北京有消息了:竟然不许!!! 他们一定是看我没有实习,这才故意驳回我的请求!
点赞 评论 收藏
分享
牛客网
牛客企业服务