codeforces 630D Hexagons!
0.5 seconds
64 megabytes
standard input
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.
The only line of the input contains one integer n (0 ≤ n ≤ 109).
Output one integer — the number of hexagons situated not farther than n cells away from a given cell.
2
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\n",m);
}
return 0;
}
codeforces 630D Hexagons!的更多相关文章
- codeforces 615E Hexagons (二分+找规律)
E. Hexagons time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round #338 (Div. 2) E. Hexagons 讨论讨论
E. Hexagons 题目连接: http://codeforces.com/contest/615/problem/E Description Ayrat is looking for the p ...
- 【38.46%】【codeforces 615E】Hexagons
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【CodeForces 615E】Hexagons
找规律. #include <cstdio> #include <iostream> #include <algorithm> #include <cstri ...
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon 数学
C. Gerald's Hexagon Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/pr ...
- Codeforces Round #313 (Div. 1) A. Gerald's Hexagon 数学题
A. Gerald's Hexagon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/p ...
- 【打CF,学算法——三星级】Codeforces Round #313 (Div. 2) C. Gerald's Hexagon
[CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/C 题面: C. Gerald's Hexagon time limit per tes ...
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon(补大三角形)
C. Gerald's Hexagon time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 【41.43%】【codeforces 560C】Gerald's Hexagon
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- Codeforces Round #247 (Div. 2) C. k-Tree (dp)
题目链接 自己的dp, 不是很好,这道dp题是 完全自己做出来的,完全没看题解,还是有点进步,虽然这个dp题比较简单. 题意:一个k叉树, 每一个对应权值1-k, 问最后相加权值为n, 且最大值至少为 ...
- 宏buf_pool_t
typedef struct buf_pool_struct buf_pool_t; struct buf_pool_struct{ /** @name General fields */ /* @{ ...
- BZOJ_1025_[SHOI2009]_游戏_(素数表+最小公倍数+DP)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1025 分析 对于\(n\),转一圈回来之后其实是好几个环各转了整数圈.这些环中的数为\(1,2 ...
- HDU 1232 畅通工程 (并查集,常规)
题意:中文题目 思路:按照HDU1213来做.http://www.cnblogs.com/xcw0754/p/4607813.html #include <bits/stdc++.h> ...
- TCP协议的一些问题
1 连接握手三次 解释1:已失效的连接请求报文段 情况下如下:client发出的第一个连接请求报文段并没有丢失,而是在某个网络结点长时间的滞留了,以致延误到连接释放以后的某个时间才到达server.本 ...
- <八>面向对象分析之UML核心元素之分析类
一:基本概念 ---->在那大数项目中,分析类是被忽视的一种非常有用的元素. ---->分析类用于获取系统中主要的“职责簇”,他们代表系统的原型类,是系统必须处 ...
- css的框架——global.css
global.css,一般这个css文件是用于装全站主要框架css样式代码. “global”翻译为全局.全部.从翻译中大家也能理解global.css用于做什么.大站常常用于装全站公共的CSS样式选 ...
- windows批处理中的%0 %1 %2 %3
原来就是参数的顺序.....倒...我还查了老半天
- HDU 5489 Removed Interval
题意:求一段序列中删掉L个连续元素后的LIS. 解法:我的想法很复杂= =怎么说呢……首先用nlogn的方法求LIS得到的序列dp的第i项的意义为上升子序列所有长度为i的序列结尾元素的最小值,那么先倒 ...
- hdu 2459 (后缀数组+RMQ)
题意:让你求一个串中连续重复次数最多的串(不重叠),如果重复的次数一样多的话就输出字典序小的那一串. 分析:有一道比这个简单一些的题spoj 687, 假设一个长度为l的子串重复出现两次,那么它必然会 ...