前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >2019.8.15乘兴打Codeforces Round #569 (Div. 2)小记A题A. Alex and a Rhombus

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

作者头像
glm233
发布2020-09-28 10:42:56
4990
发布2020-09-28 10:42:56
举报

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+

\sum_{i=1}^{n}4i-4
\sum_{i=1}^{n}4i-4

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

代码语言:javascript
复制
#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;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/08/15 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档