zoukankan      html  css  js  c++  java
  • codeforces 630D Hexagons!

    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.

    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

    题意:如图,当有n层时,问总共有多少个六边形
    题解:观察图形发现第0层有1个六边形,第1层有6个 第2层12个依次类推第n层有6*(n-1)个,则 当有n层时总共有1+1*6+2*6+3*6+...+n*6个提取公因数6则
    1到n的和为n*(n-1)/2

    #include<stdio.h>       //d
    #include<string.h>
    #include<stdlib.h>
    #include<algorithm>
    #include<math.h>
    #include<queue>
    #include<stack>
    #define INF 0x3f3f3f
    #define MAX 100100
    #define LL long long
    using namespace std;
    int main()
    {
    	LL n,m,j,i;
    	while(scanf("%lld",&n)!=EOF)
    	{
    		n=n*(n+1)/2;
    		m=n*6+1;
    		printf("%lld
    ",m);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    js笔记1
    106. Construct Binary Tree from Inorder and Postorder Traversal根据后中序数组恢复出原来的树
    365. Water and Jug Problem量杯灌水问题
    452. Minimum Number of Arrows to Burst Balloons扎气球的个数最少
    650. 2 Keys Keyboard复制粘贴的次数
    249. Group Shifted Strings把迁移后相同的字符串集合起来
    450. Delete Node in a BST 删除bst中的一个节点
    528. Random Pick with Weight index的随机发生器
    582. Kill Process杀死所有子代
    348. Design Tic-Tac-Toe设计井字游戏
  • 原文地址:https://www.cnblogs.com/tonghao/p/5202138.html
Copyright © 2011-2022 走看看