1537.Tiger Eat People SDNUOJ1537(2018总结赛)

Description
As we all know, lls is the boss of SDNU ACM Training Team, so many team members may be afraid of him.

But this is not the case, lls is very kindly to us. To show his love to us, he plan to give all of us an “Accepted”. The problem shows as follows:
There are n numbers ​.Each time you can choose a subset of them(may be empty), and then add them up.Count how many numbers can be represented in this way.
Input
The first line of the input contains an integer T, denoting the number of test cases.
In each test case, there is a single integers n in one line, as described above.
, ​
Output
For each test case, output one line contains a single integer, denoting the answer.
Sample Input
4
9
7
8
233
Sample Output
512
128
256
13803492693581127574869511724554050904902217944340773110325048447598592

AC代码(这就是模拟吗,有比这简单很多的方法)

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;


void solve(int n)
{
    char a[10005] = "2";
            char sum[10005];
            for(int k = 0; k < n - 1; ++k)
            {
                int len = strlen(a);
//            cout << "a的长度 : " << len << '\n';
                int j = 0;
                int i = 0;
                for(; i < len; ++i)
                {
                    sum[i] = (a[i] + a[i] - '0' - '0' + j ) % 10 + '0';
//                cout << "该位的和对10取余" << sum[i] << '\n';
                    j = (a[i] + a[i] - '0' - '0' + j ) / 10;
//                cout << "该位进位" << j << '\n';
                }
                if(j != 0)
                {
                    sum[i] = j + '0';
//                cout << "最后一位的进位处理" << sum[i] << '\n';
                }
                strcpy(a, sum);
//            cout << "当前的a " << a << '\n';
            }
            if(n == 1)
                strcpy(sum, a);
            if(n == 0)
                strcpy(sum, "1");
//        reverse(sum, sum + sizeof(sum));
            reverse(sum, sum + strlen(sum));
            cout << sum << '\n';
            memset(sum, 0, sizeof(sum));
            memset(a, 0, sizeof(a));
}

int main()
{
    int t;
    while(~scanf("%d", &t))
    {
        for(int m = 0; m < t; ++m)
        {
            int n;
            cin >> n;
            solve(n);
        }
    }
    return 0;
}

简单版

#include <iostream>
#include <iomanip>
//#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
//        double n;
        int n;
        cin >> n;
        ///std::setprecision(n)控制输出n位有效数字
        ///与fixed连用表示控制输出到小数点后n位
        cout << fixed << std::setprecision(0) << pow(2, n) << '\n' ;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/zhaobaole2018/article/details/85097597