Codeforces Experimental Educational Round: VolBIT Formulas Blitz D. Hexagons!
2016-02-19 10:36
405 查看
D. Hexagons!
time limit per test
0.5 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output
After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-based fights
of big squadrons of enemies on infinite fields where every cell is in form of a hexagon.
Some of magic effects are able to affect several field cells at once, cells that are situated not farther than n cells away from the
cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another.
It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases, so it can adversely affect the
game performance. That's why Petya decided to write a program that can, given n, determine the number of cells that should be repainted
after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than n cells
away from a given cell.
Input
The only line of the input contains one integer n (0 ≤ n ≤ 109).
Output
Output one integer — the number of hexagons situated not farther than n cells away from a given cell.
Examples
input
output
从图中可以推导出
1: 7
2: 19
3: 37
4: 61
很显然推出一个公式:n*(n+1)*3+1
time limit per test
0.5 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output
After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-based fights
of big squadrons of enemies on infinite fields where every cell is in form of a hexagon.
Some of magic effects are able to affect several field cells at once, cells that are situated not farther than n cells away from the
cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another.
It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases, so it can adversely affect the
game performance. That's why Petya decided to write a program that can, given n, determine the number of cells that should be repainted
after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than n cells
away from a given cell.
Input
The only line of the input contains one integer n (0 ≤ n ≤ 109).
Output
Output one integer — the number of hexagons situated not farther than n cells away from a given cell.
Examples
input
2
output
19
从图中可以推导出
1: 7
2: 19
3: 37
4: 61
很显然推出一个公式:n*(n+1)*3+1
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin>>n; cout<<(n+1)*n*3+1<<endl; return 0; }
相关文章推荐
- golang float32/64与[]byte互转
- 114. Flatten Binary Tree to Linked List
- golang.org/x/mobile/exp/gl/glutil/glimage.go 源码分析
- Go语言基于Socket编写服务器端与客户端通信的实例
- AlphaGo的新技能学习过程
- VIEWGOOD(远古)新疆军区流媒体应用需求
- Going Home(最小费用最大流模板)
- 在Django中使用markdown
- Logo图标快速生成软件(Sothink Logo Maker) v3.5 官方设计师版
- Django环境搭建
- Zxing生产二维码 附带添加logo
- 关于分类category与类扩展extension的区别
- Ubuntu之Gitlab、Gerrit、Jenkins协调工作配置之部分三:
- 分享几张golang桌面图片
- 怎么限制Google自己主动调整字体大小
- Go语言并发与并行学习笔记(二)
- Django model relationship field
- Google Breakpad使用
- Go语言并发与并行学习笔记(一)
- 【详解】django项目中查询数据量