HDU--1290--切西瓜

题意:一刀切,切的立体图形最大块数;

Input

输入数据包含多个测试实例,每个实例占一行,每行包含一个整数n(1<=n<=1000),表示切的刀数。

Output

对于每组输入数据,请输出对应的蛋糕块数,每个测试实例输出一行。

Sample Input
1
2
3
Sample Output
2
4
8

思路:太难找递推方程,一般情况下立体图形方程形式ax^3+bx^2+cx+d,求着四个参数就可以了;平面图形是ax^2+bx+c;

注意:代码如下,输出的数据int类型亦可;

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		printf("%d\n",(n*n*n+5*n+6)/6);
	}
} 
发布了170 篇原创文章 · 获赞 73 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/queque_heiya/article/details/104454942