2019.8.15乘兴打Codeforces Round #569 (Div. 2)小记A题A. Alex and a Rhombus

时间:2022-07-25
本文章向大家介绍2019.8.15乘兴打Codeforces Round #569 (Div. 2)小记A题A. Alex and a Rhombus,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

A. Alex and a Rhombus time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output While playing with geometric figures Alex has accidentally invented a concept of a nn-th order rhombus in a cell grid.

A 1-st order rhombus is just a square 1×1 (i.e just a cell).

A n-th order rhombus for all n≥2n≥2 one obtains from a n−1-th order rhombus adding all cells which have a common side with it to it (look at the picture to understand it better).

Input The first and only input line contains integer nn (1≤n≤100) — order of a rhombus whose numbers of cells should be computed.

Output Print exactly one integer — the number of cells in a nn-th order rhombus.

Examples inputCopy 1 outputCopy 1 inputCopy 2 outputCopy 5 inputCopy 3 outputCopy 13 Note Images of rhombus corresponding to the examples are given in the statement.

思路:找规律:a1=1,a2=1+4,a3=1+4+8,a4=1+4+8+12

故答案为an=1+

=2*n*n-2*n+1

#include<bits/stdc++.h>
#define rg register long long
#define inf 21474899993647
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define ll long long
#define maxn 100005
#define endl "n"
#define   N 6000
const double eps=1e-8;
using namespace std;
inline ll read()
{
    char ch=getchar();
    ll s=0,w=1;
    while(ch<48||ch>57)
    {
        if(ch=='-')
            w=-1;
        ch=getchar();
    }
    while(ch>=48&&ch<=57)
    {
        s=(s<<1)+(s<<3)+(ch^48);
        ch=getchar();
    }
    return s*w;
}
inline void write(ll x)
{
    if(x<0)
        putchar('-'),x=-x;
    if(x>9)
        write(x/10);
    putchar(x%10+48);
}
ll n=read();
ll ans=1;
int main()
{
    ll tot=4;
while(n!=1)
{
    ans+=tot;
    tot+=4;
    n--;
}
 
    cout<<ans<<endl;
 
    return 0;
}