Welcome

首页 / 软件开发 / 数据结构与算法 / UVa 10182 Bee Maja:规律&O(1)算法

UVa 10182 Bee Maja:规律&O(1)算法2014-07-28 csdn博客 synapse7

10182 - Bee Maja

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1123

Maja is a bee. She lives in a bee hive with thousands of other bees. This bee hive consists of many hexagonal honey combs where the honey is stored in. But bee Maja has a problem. Willi told her where she can meet him, but because Willi is a male drone and Maja is a female worker they have different coordinate systems.

Maja"s Coordinate SystemWilli"s Coordinate System
Maja who often flies directly to a special honey comb has laid an advanced two dimensional grid over the whole hive.Willi who is more lazy and often walks around just numbered the cells clockwise starting from 1 in the middle of the hive.
Help Maja to convert Willi"s system to hers. Write a program which for a given honey comb number gives the coordinates in Maja"s system.

Input Specification

The input file contains one or more integers which represent Willi"s numbers. Each number stands on its own in a separate line, directly followed by a newline. The honey comb numbers are all less than 100 000.

Output Specification

You should output the corresponding Maja coordinates to Willi"s numbers, each coordinate pair on a separate line.

Sample Input

12345

Sample Output

0 00 1-1 1-1 00 -1
O(1)复杂度的思路:这道题如果只看左边那个图的话就会发现竖着的每一列纵坐标相同,而向左下方斜着的每一列纵坐标相同。但是这样并不能找出这些点的关系,其实换个角度,如果把左边的坐标在直角坐标系上画出来,就比较容易看出这是一个很有规律的一个图,只需要横纵坐标的加减就好了,至于加减多少那就看这个数所在的层数,层数可以根据x轴上的坐标的通项求出。