哔哩哔哩 2019校园招聘 开发工程师-2018.09.21

版权声明:本人ZZU在校学生,文章均为个人心得,有不足之处请不吝赐教! https://blog.csdn.net/whl_program/article/details/82803145

1-1
1-2.png
思路:
从后往前思考,偶数用扭蛋机3号,奇数用扭蛋机2号,每次更改n的值,统计路径
代码:

#include <bits/stdc++.h>

using namespace std;
int n;
int main()
{
    string res = "";
    cin >> n;
    while(n != 0){
        if(n % 2 == 0){
            n = (n-2)/2;
            res = '3' + res;
        }else{
            n = (n-1)/2;
            res = '2' + res;
        }
    }
    cout << res << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/whl_program/article/details/82803145