链接:
https://codeforces.com/contest/1180/problem/A
题意:
While playing with geometric figures Alex has accidentally invented a concept of a n-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≥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).
Alex asks you to compute the number of cells in a n-th order rhombus.
思路:
没增加一层,最外层的正方形增加4个。
累加计算。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[100];
int main()
{
int n;
cin >> n;
int res = 1;
int cnt = 4;
for (int i = 2;i <= n;i++)
{
res += cnt;
cnt += 4;
}
cout << res << endl;
return 0;
}