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;
}

 

转载于:https://www.cnblogs.com/Vampire6/p/11106869.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值