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

左手的ㄟ右手 2022-01-07 15:35 313阅读 0赞

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.

1705372-20190629160529011-1498659285.png

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

  1. #include<bits/stdc++.h>
  2. typedef long long ll;
  3. using namespace std;
  4. const int maxn=2e5+7;
  5. ll ji[maxn];
  6. int main()
  7. {
  8. int n;
  9. while(cin>>n) {
  10. ll ji[maxn];
  11. ji[0]=1;
  12. for(int i=1;i<205;i++)
  13. {
  14. ji[i]=ji[i-1]+2;
  15. }
  16. if (n == 1)
  17. cout << 1 << endl;
  18. else if (n == 2)
  19. cout << 5 << endl;
  20. else {
  21. ll sum = 0;
  22. for (int i = 0; i <= n - 2; i++)
  23. {
  24. sum += ji[i];
  25. }
  26. cout << 2 * sum + ji[n - 1] << endl;
  27. }
  28. }
  29. return 0;
  30. }

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

发表评论

表情:
评论列表 (有 0 条评论,313人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Codeforces Round #556 (Div. 2) A

    题面很简单,思路就是简单贪心,si数组是贮存购买数组,bi数组是贮存出售数组,题面是给你r的货币,让你通过出售和购买来获取最大价值,第一种算法是通过找出bi数组最大值,和si数