Hexagons!(找规律)
2016-03-11 12:05
417 查看
Hexagons!
Crawling in process...
Crawling failed
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
题意:求不超过数字n的所有细胞总数。
当n=0时,有一个f(0)
当n=1时,外层是个6边形,可以看做每条边有2个细胞,不过每条边的第一个细胞和最后一个细胞被用2次。外层有:(!+1)*6-6
当n2时,外层也是个6变形,每条边有3个细胞,不过每条边的第一个细胞和最后一个细胞被用2次 . 外层有: (2+1)*6-6
""""""""""
n时,外层是个6变形,每条边有(n+1)个细胞,不过每条边的第一个细胞和最后一个细胞被用2次 . 外层共有:(n+1)*6-6个细胞
把上面每层细胞求和可得:
sum=3*n*(n+1)+1;
My solution:
/*2016.3.11*/
#include<stdio.h>
int main()
{
int i;
long long ans,n;
while(scanf("%I64d",&n)==1)
{
ans=3*n*(n+1)+1;
printf("%I64d\n",ans);
}
return 0;
}
Crawling in process...
Crawling failed
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
题意:求不超过数字n的所有细胞总数。
当n=0时,有一个f(0)
当n=1时,外层是个6边形,可以看做每条边有2个细胞,不过每条边的第一个细胞和最后一个细胞被用2次。外层有:(!+1)*6-6
当n2时,外层也是个6变形,每条边有3个细胞,不过每条边的第一个细胞和最后一个细胞被用2次 . 外层有: (2+1)*6-6
""""""""""
n时,外层是个6变形,每条边有(n+1)个细胞,不过每条边的第一个细胞和最后一个细胞被用2次 . 外层共有:(n+1)*6-6个细胞
把上面每层细胞求和可得:
sum=3*n*(n+1)+1;
My solution:
/*2016.3.11*/
#include<stdio.h>
int main()
{
int i;
long long ans,n;
while(scanf("%I64d",&n)==1)
{
ans=3*n*(n+1)+1;
printf("%I64d\n",ans);
}
return 0;
}
相关文章推荐
- 北邮Google大牛本科研究生总结~
- 欧拉项目第九题 Special Pythagorean triplet
- golang go语言与C语言互调,通过cgo
- Go 语言运行时环境变量快速导览
- 我与小娜(33):AlphaGo又胜一局
- AlphaGo是如何下棋的?
- SSL renegotiation with full duplex socket communic
- SSL renegotiation with full duplex socket communic
- SENGO森果网—全球婚礼事业合作伙伴
- go使用时间作为种子生成随机数
- django环境搭建
- VIEWGOOD(远古)数字图书馆解决方案
- Go语言开发环境搭建
- MongoClient类
- Codeforces 633H. Fibonacci-ish II (Mo's Algorithm(莫队算法) + 线段树 + 离散化)
- sougou
- 详解Google-ProtoBuf中结构化数据的编码
- Google Chrome is unresponsive. Relaunch now?
- 六.Django中URL的参数传递
- Sublime Text 2搭建Go开发环境(Windows)