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+;
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 ;
}
最新文章
- 特殊的对象引用---$this
- dos笔记
- Windows下安装Nginx反向代理服务器
- ACM/ICPC 之 BFS+状态压缩(POJ1324(ZOJ1361))
- oracle dataguard (一)
- Frame - 快速创建高品质的 Web 应用原型
- 【扩展】Canvas绘制列表的尝试
- NOIP2013 货车运输
- appcan 跨窗口处理方法 appcan.window.evaluateScript({name,scriptContent,type})使用解读
- BZOJ_1208_&;_Codevs_1258_[HNOI2004]_宠物收养所_(平衡树/set)
- LSI SAS 3008配置操作
- DataGridView显示行号
- 零基础学Python--------第11章 使用Python操作数据库
- 大数据ssh疑点跟踪
- springMVC_04controller四种配置总结
- Java使用HTTPClient3.0.1开发的公众平台消息模板的推送功能
- 多数据源springboot-jta-atomikos
- 获取TrustedInstaller
- django model 数据类型
- CentOS 装hadoop3.0.3 版本踩坑
热门文章
- C#实现万年历(农历、节气、节日、星座、星宿、属相、生肖、闰年月、时辰)
- matlab 警告(warning)、错误(error)、异常(exception)与断言(assert)
- arcserver开发小结(三)
- 零元学Expression Design 4 - Chapter 7 使用内建功能「Clone」来达成Path的影分身之术
- 亲串 (hdu 2203 KMP)
- HTML5 课程
- WPF的Timer控件的使用
- Apache 配置两个域名匹配的文件夹和配置多个Web站点
- 关于在.Net开发中使用Sqlite的版本选择问题
- Thinkphp模板开放给第三方编辑权限时,如何禁止模板使用php代码