Codeforces Round #569 (Div. 2)A. Alex and a Rhombus

A. Alex and a Rhombus

题目链接:http://codeforces.com/contest/1180/problem/A

题目:

While playing with geometric figures Alex has accidentally invented a concept of an-th order rhombusin a cell grid.A1-st order rhombusis just a square1×1(i.e just a cell).An-th order rhombusfor alln≥2one obtains from an−1-th order rhombusadding all cells which have a common side with it to it (look at the picture to understand it better).

Alex asks you to compute the number of cells in a n-th order rhombus.
InputThe first and only input line contains integern(1≤n≤100) — order of a rhombus whose numbers of cells should be computed.
OutputPrint exactly one integer — the number of cells in a n-th order rhombus.


Examples


Input
1
Output
1
Input
2
Output
5
Input
3
Output
13
NoteImages of rhombus corresponding to the examples are given in the statement.


题意:求第N个图形的小方格个数

思路:

找规律题:

1+3+5+7+..+5+3+1

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn=2e5+7;
ll ji[maxn];
int main()
{
        int n;
        while(cin>>n) {
            ll ji[maxn];
            ji[0]=1;
            for(int i=1;i<205;i++)
            {
                ji[i]=ji[i-1]+2;
            }
            if (n == 1)
                cout << 1 << endl;
            else if (n == 2)
                cout << 5 << endl;
            else {
                ll sum = 0;
                for (int i = 0; i <= n - 2; i++)
                {
                    sum += ji[i];
                }
                cout << 2 * sum + ji[n - 1] << endl;
            }
        }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Vampire6/p/11106869.html