CODEFORCES630D-Hexagons!

本文介绍了一款策略游戏中魔法效果影响范围的计算方法,通过数学公式快速确定受影响的六边形格子数量,帮助游戏设计师平衡效果规模与游戏性能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 Hexagons!
Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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);
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值