Codeforces 630D Hexagons!
2016-04-09 20:25
483 查看
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.
![](http://codeforces.com/predownloaded/ac/2a/ac2ac560c01da0448913a2def8ccd952f86d8559.png)
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
观察图形,找规律
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.
![](http://codeforces.com/predownloaded/ac/2a/ac2ac560c01da0448913a2def8ccd952f86d8559.png)
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
观察图形,找规律
#include <iostream> #include<cstdio> #include<cstring> #include<vector> #include<queue> #include<stack> #include<algorithm> using namespace std; int main() { long long n,sum; while(~scanf("%I64d",&n)) { if(n==0) sum=1; else { sum=n*(n+1)/2*6+1; } printf("%I64d\n",sum); } return 0; }
相关文章推荐
- com.google.gson.internal.StringMap cannot be cast XXX
- MangoDB 安装过程
- Go语言顺序编程
- 10种可提高应用在Google Play上的曝光率的正确做法
- mongo db sharding introduction
- View.INVISIBLE和View.GONE的区别
- POJ-2195-Going Home(最小费用最大流/二分图)
- golang map使用
- golang中channel的超时处理
- 2016 Google code jam 大赛
- scanf,输入 Go west, young man!
- 求强连通分量的双DFS,Tarjan和Gobow算法详解
- django-其他(内容多了再做分类)
- django-表单
- django-视图
- django-模板
- 译:Google的大规模集群管理工具Borg(一)------ 用户视角的Borg特性
- HDU 5512 Pagodas【博弈】
- HDU 5512 Pagodas【博弈】
- golang信号处理