1506:吃饼干
描述
有 m 块饼干,每天至少吃一块,至多全吃完,问总共有多少种吃法。
输入
只有一组案例,包含一个正整数 m 代表有 m 块饼干。
对于 30% 的样例有 m <= 30。
对于 60% 的样例有 m <= 60。
对于 100% 的样例有 m <= 100。
输出
有多少种吃法,然后换行。
样例输入
3
样例输出
4
//先是通过数学归纳法可以发现饼干数量的规律
//大数乘法的使用
#include<iostream>
#include<cmath>
#include<string>
#include<string.h>
#include<algorithm>
#include<limits.h>
using namespace std;
typedef long long int ll;
string bigchen(string std1, string std2)
{
string res;
int length1 = std1.length();
int length2 = std2.length();
int result[90] = { 0 };
int a[40] = { 0 };
int b[2] = { 0 };
int i = 0, j = 0;
for (i = length1 - 1, j = 0; i >= 0; i--, j++)
{
a[j] = std1[i] - '0';
}
for (i = length2 - 1, j = 0; i >= 0; i--, j++)
{
b[j] = std2[i] - '0';
}
for (i = 0; i < length1; i++)
{
for (j = 0; j < length2; j++)
{
result[i + j] += a[i] * b[j];
}
}
for (i = 0; i < (length1 + length2); i++)
{
if (result[i] > 9)
{
result[i + 1] += result[i] / 10;
result[i] %= 10;
}
}
for (i = length1 + length2; i >= 0; i--)
{
if (result[i] == 0)
{
continue;
}
else
{
break;
}
}
for (; i >= 0; i--)//上面循环出来的i继续运算
{
if (result[i] <= 9)
{
res = res + char('0' + result[i]);
}
else
{
res = res + char('0' + result[i] / 10) + char('0' + result[i] % 10);
}
}
return res;
}
int main()
{
int m;
cin >> m;
string q = "1";
for (int i = 1; i < m; i++)
{
q = bigchen(q, "2");
}
//相当于2的m-1次方
cout << q << endl;
}

被折叠的 条评论
为什么被折叠?



