现在的位置: 首页 > 综合 > 正文

UVa 10079 – Pizza Cutting

2013年09月07日 ⁄ 综合 ⁄ 共 348字 ⁄ 字号 评论关闭

题目:用刀切pizza,n刀最多能切几块。

分析:数学题。n条直线最多将平面分成n(n+1)/2+1块区域。

推导:设n条直线分平面为f(n)块。那么第n+1条之间最多和前n条直线都相交,故有n个交点。

            会形成n-1条线段和两条射线,他们会把原有的n+1个区域分成两部分

            所以有递推公式:f(n+1) = f(n)+n+1,f(0) = 1

            求解:f(n) = n(n+1)/2+1

#include <iostream>
#include <cstdlib>
#include <cstdio>

using namespace std;

int main()
{
	long long n;
	while ( cin >> n && n >= 0LL ) 
		cout << n*(n+1LL)/2LL+1LL << endl;
	
	return 0;
}

抱歉!评论已关闭.