CODEFORCES630D-Hexagons!
来源:互联网 发布:linux 赋值 命令结果 编辑:程序博客网 时间:2024/06/10 11:38
Description
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.
Sample Input
2
19
找规律题:一开始以为是递推,自己斜着看了下,发现可以有一个推导 :
就上图说吧!从右下45度向左上45度看 六边形的个数为4+5+6+7+6+5+4;
第n个则为((n+1)+(n+2)+。。。+(n+n))*2+2*n+1 对应(4+5+6)*2+7
ac代码:
#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>using namespace std;int main(){ __int64 n; while(scanf("%I64d",&n)!=EOF) { printf("%I64d\n",3*n*n+3*n+1); }}
- CODEFORCES630D-Hexagons!
- C-Hexagons!
- D - Hexagons!
- CodeForces Hexagons!
- A. Tiling with Hexagons
- CF 615E Hexagons
- CF 338 Hexagons
- COdeforces 630D Hexagons!
- CodeForces 630D-Hexagons!
- Hexagons!(找规律)
- Codeforces 630D Hexagons!
- CodeForces 615E Hexagons
- codeforce #630 D. Hexagons!
- Codeforece - 630 - D. Hexagons!
- CodeForces 630D:Hexagons!【水】
- 【38.46%】【codeforces 615E】Hexagons
- CF 216A - Tiling with Hexagons
- CF 216 A Tiling with Hexagons
- linux 比较两个文件夹下的内容
- KVO and KVC
- NOJ1143 字母转换
- 推荐一个设置鼠标cursor图标的网站、将PNG转换成ICO
- mysql int转换成string时类型要用char
- CODEFORCES630D-Hexagons!
- JavaScript学习 - 数组
- FPGA定时器的计数设置,是否要减1?(精密计数)
- IntelliJ-Idea工具的常用快捷键和在html里的常用快捷键
- 我的2015
- LEETCODE 125
- 630A. Again Twenty Five!
- 146.Evaluate the following SQL statement:
- IOS网络支持库AFNetworking(1)