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+;
ll ji[maxn];
int main()
{
int n;
while(cin>>n) {
ll ji[maxn];
ji[]=;
for(int i=;i<;i++)
{
ji[i]=ji[i-]+;
}
if (n == )
cout << << endl;
else if (n == )
cout << << endl;
else {
ll sum = ;
for (int i = ; i <= n - ; i++)
{
sum += ji[i];
}
cout << * sum + ji[n - ] << endl;
}
}
return ;
}

最新文章

  1. 特殊的对象引用---$this
  2. dos笔记
  3. Windows下安装Nginx反向代理服务器
  4. ACM/ICPC 之 BFS+状态压缩(POJ1324(ZOJ1361))
  5. oracle dataguard (一)
  6. Frame - 快速创建高品质的 Web 应用原型
  7. 【扩展】Canvas绘制列表的尝试
  8. NOIP2013 货车运输
  9. appcan 跨窗口处理方法 appcan.window.evaluateScript({name,scriptContent,type})使用解读
  10. BZOJ_1208_&amp;_Codevs_1258_[HNOI2004]_宠物收养所_(平衡树/set)
  11. LSI SAS 3008配置操作
  12. DataGridView显示行号
  13. 零基础学Python--------第11章 使用Python操作数据库
  14. 大数据ssh疑点跟踪
  15. springMVC_04controller四种配置总结
  16. Java使用HTTPClient3.0.1开发的公众平台消息模板的推送功能
  17. 多数据源springboot-jta-atomikos
  18. 获取TrustedInstaller
  19. django model 数据类型
  20. CentOS 装hadoop3.0.3 版本踩坑

热门文章

  1. C#实现万年历(农历、节气、节日、星座、星宿、属相、生肖、闰年月、时辰)
  2. matlab 警告(warning)、错误(error)、异常(exception)与断言(assert)
  3. arcserver开发小结(三)
  4. 零元学Expression Design 4 - Chapter 7 使用内建功能「Clone」来达成Path的影分身之术
  5. 亲串 (hdu 2203 KMP)
  6. HTML5 课程
  7. WPF的Timer控件的使用
  8. Apache 配置两个域名匹配的文件夹和配置多个Web站点
  9. 关于在.Net开发中使用Sqlite的版本选择问题
  10. Thinkphp模板开放给第三方编辑权限时,如何禁止模板使用php代码