版权声明:本人原创文章若需转载请标明出处和作者!沙 https://blog.csdn.net/weixin_44143702/article/details/88386302
王小二切饼
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
王小二自夸刀工不错,有人放一张大的煎饼在砧板上,问他:“饼不许离开砧板,切n(1<=n<=100)刀最多能分成多少块?”
Input
输入切的刀数n。
Output
输出为切n刀最多切的饼的块数。
Sample Input
100
Sample Output
5051
切第n刀时最多可以与前面的n-1刀相交,最多经过n个区域,所以多出的块数为n块
切饼问题详解:
1. https://blog.csdn.net/lanxu_yy/article/details/18654297
#include <stdio.h>
#include <stdlib.h>
long long int a[105];///注意定义为 long long int 防止存放数据超范围
int main()
{
int n, i;
a[1] = 2;
a[2] = 4;
a[3] = 7;
a[4] = 11;
for(i = 4; i <= 100; i++)
{
a[i] = a[i - 1] + i;
}
while(~scanf("%d", &n))
{
printf("%lld\n", a[n]);
}
return 0;
}