HDU 2050 折线分割平面

递推+猜结论?(也不算猜的

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cctype>

using namespace std;

inline void read(long long &x)
{
    int k = 1; x = 0;
    char c = getchar();
    while (!isdigit(c))
        if (c == '-') k = - 1, c = getchar();
        else c = getchar();
    while (isdigit(c))
        x = (x << 1) + (x << 3) + (c ^ 48),
        c = getchar();
    x *= k;
}

long long T, n, cm, dp[10101];

int main()
{
    read(T);
    for (int plk = 1; plk <= T; ++plk)
    {
        read(n);
        memset(dp, 0, sizeof(dp));
        dp[0] = 0, dp[1] = 2; cm = 5;
        for (int i = 2; i <= n; ++i)
            dp[i] = dp[i - 1] + cm, cm += 4; 
        printf("%lld\n", dp[n]);
    }
    return 0;
}

 

posted @ 2018-12-13 11:15  Christopher_Yan  阅读(136)  评论(0编辑  收藏  举报