CODEFORCES630D-Hexagons!
2016-03-09 17:16
381 查看
Hexagons!
Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d
& %I64u
Submit Status
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
Input
Output
Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d
& %I64u
Submit Status
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
Input
2
Output
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); } }
相关文章推荐
- 一道2年级数学题 10人做9人错
- HDU-1163Eddy's digital Roots
- TOJ 3051
- TOJ 1537
- TOJ 1252
- TOJ 2544
- TOJ 2399
- TOJ 2646
- TOJ 1981
- TOJ 2814
- TOJ 1255
- 1920. Divide The Stones
- TYVJ P1875 [NOIP1999P1]Cantor表
- TYVJ P1334 powermax
- Sicily 1327 Pinary
- UVa 202 Repeating Decimals
- Sicily 1209 Sequence Sum Possibi
- Sicily 1166 Computer Transformat
- Sicily 2010 H Number
- Sicily 6084 Times17