2019.8.15乘兴打Codeforces Round #569 (Div. 2)小记A题A. Alex and a Rhombus
A. Alex and a Rhombus time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output While playing with geometric figures Alex has accidentally invented a concept of a nn-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≥2n≥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).
Input The first and only input line contains integer nn (1≤n≤100) — order of a rhombus whose numbers of cells should be computed.
Output Print exactly one integer — the number of cells in a nn-th order rhombus.
Examples inputCopy 1 outputCopy 1 inputCopy 2 outputCopy 5 inputCopy 3 outputCopy 13 Note Images of rhombus corresponding to the examples are given in the statement.
思路:找规律:a1=1,a2=1+4,a3=1+4+8,a4=1+4+8+12
故答案为an=1+
=2*n*n-2*n+1
#include<bits/stdc++.h>
#define rg register long long
#define inf 21474899993647
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define ll long long
#define maxn 100005
#define endl "n"
#define N 6000
const double eps=1e-8;
using namespace std;
inline ll read()
{
char ch=getchar();
ll s=0,w=1;
while(ch<48||ch>57)
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(ch>=48&&ch<=57)
{
s=(s<<1)+(s<<3)+(ch^48);
ch=getchar();
}
return s*w;
}
inline void write(ll x)
{
if(x<0)
putchar('-'),x=-x;
if(x>9)
write(x/10);
putchar(x%10+48);
}
ll n=read();
ll ans=1;
int main()
{
ll tot=4;
while(n!=1)
{
ans+=tot;
tot+=4;
n--;
}
cout<<ans<<endl;
return 0;
}
- 通过shell脚本来统计段大小(r5笔记第14天)
- Linux下配置MySQL主从复制(r5笔记第13天)
- Final 关键字
- ArrayList 和 LinkedList的执行效率比较
- 关于consistent gets(r5笔记第12天)
- wait/notify 实现多线程交叉备份
- 01.SVN介绍与安装
- 由sqlplus中的一个小细节所做的折腾(r5笔记第11天)
- 浅析多线程的对象锁和Class锁
- 使用strace诊断奇怪的sqlplus登录问题(r5笔记第29天)
- 读书笔记 之《Thinking in Java》(对象、集合、异常)
- 深度解析dba_segments和sys.seg$中的细节差异(上) (r5笔记第27天)
- 【大牛经验】26种语言输出HelloWord
- 深度解析dba_segments和sys.seg$中的细节差异(下) (r5笔记第28天)
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- FatFs-目录下文件扫描
- Python之Bilibili自动更新邮件提醒并任务栏图标「完整代码」
- STC15频率产生器(粗调+微调+数码管显示)完整代码
- PID算法原理、调整规律及代码
- GIT——分布式版本控制系统
- 如何在 PHP 中使用和管理 Cookie
- 玩转 PhpStorm 系列(九):代码调试篇(上)
- 在 PHP 中使用和管理 Session
- STC51单片机中断与定时器配置参考
- 玩转 PhpStorm 系列(十):代码调试篇(下)
- STM32字符串转整数
- Java常用设计模式--代理模式(Proxy Pattern)
- 详解爬取搜狐号自媒体的所有文章
- 笑了,面试官问我知不知道异步编程的Future。
- ES6之let和const命令