zoukankan      html  css  js  c++  java
  • Codeforces--630D--Hexagons(规律)

    
    D - Hexagons!

    Crawling in process... Crawling failed 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
    1,6,12,18....明显就是1,1*6,2*6,3*6....除了第一项,就是一个等差序列带公式就行了
    #include<iostream>
    using namespace std;
    #define LL long long
    int main()
    {
    	LL n;
        cin>>n;
        cout<<n*(6+6*n)/2+1<<endl;
        return 0;
    }
    
    

    
    
  • 相关阅读:
    hive on tez自定义jobname
    hive血缘关系之输入表与目标表的解析
    spark ml中一个比较通用的transformer
    TF-IDF小记
    namenode服务迁移
    spark on yarn上的dynamic executor
    zookeeper集群线上机器置换
    namenode元数据容错
    Spark HistoryServer服务迁移
    Java中Webservice调用.NET天气接口生成客户端异常
  • 原文地址:https://www.cnblogs.com/playboy307/p/5273414.html
Copyright © 2011-2022 走看看