码迷,mamicode.com
首页 > 其他好文 > 详细

10079 - Pizza Cutting

时间:2014-09-17 12:09:02      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   io   os   ar   for   sp   代码   

点击打开链接


题意:用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;
}


10079 - Pizza Cutting

标签:style   http   color   io   os   ar   for   sp   代码   

原文地址:http://blog.csdn.net/u011345461/article/details/39339669

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!