题意:用n刀可以切出最多块的Pizza。
思路:线段相交越多,所分成的区域越多。每多一刀,就让这刀与之前的全部相交,即为最大值。最后有公式的:n * (n + 1) / 2 + 1
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
ll n;
ll sovle(ll k) {
if (n == 0)
return 1;
if (n == 1)
return 2;
ll ans = 2;
for (ll i = 2; i <= k; i++)
ans += i;
return ans;
}
int main() {
while (scanf("%lld", &n) && (n >= 0)) {
ll ans = sovle(n);
printf("%lld\n", ans);
}
return 0;
}