C-Hexagons!
来源:互联网 发布:vb能做到人脸识别吗 编辑:程序博客网 时间:2024/06/06 05:27
C - Hexagons!
Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit
Status
Practice
CodeForces 630D
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=0,只有1个图形,n=1时有1+6个,输入n,求出前n层内共有几个六边形
这题不坑啊,就是找规律,居然只有我一个做出来。。。
n 数量
0 1
1 7
2 19
3 37
4 61
如果还不清晰,那接着往下看
n 数量
0 6*0
1 6*0+6*1
2 6*0+6*1+6*2
3 6*0+6*1+6*2+6*3
4 6*0+6*1+6*2+6*3+6*4
总数sum=6(1+…..+n)=6*n(n-1)/2; n>0
sum=1 n=0
代码
#include<cstdio>#include<stack>#include<cstring>#include<cctype>#include<cstdlib>using namespace std;int main(){ long long int n; while(scanf("%lld",&n)!=EOF) { if(n==0) printf("1\n"); else printf("%lld\n",6*n*(n+1)/2+1); } return 0;}
- C-Hexagons!
- D - Hexagons!
- CODEFORCES630D-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
- calc在布局中的使用
- 合唱队(未完成)
- mysql在我的windows的安装
- 第23讲项目2——乱玩数字
- Mac OS中添加环境变量
- C-Hexagons!
- Widget对应QWidget类的用法
- 看完这个,你还认为自己懂勾股定理吗?
- 剑指offer题目记录
- HDU 1260 Tickets (简单DP)
- [LeetCode]318. Maximum Product of Word Lengths
- 3876: [Ahoi2014]支线剧情 有上下界的费用流
- 初等数论四大定理之——费马小定理
- spring的aop 基于schema