UVa 10182 Bee Maja: Rule &o (1) algorithm

Source: Internet
Author: User
Tags time limit

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 the other bees. This bee hive consists of many hexagonal honey combs where the honey are stored in. But Bee Maja has a problem. Willi told her where she can meet him, but because, Willi are a male drone and Maja is a female worker they have different C Oordinate systems.

Maja ' s coordinate System Willi ' s coordinate System
maja who often flies directly to a special honey the comb has the laid a advanced two dimensional grid over the whole hive. willi who are more lazy and often walks around just the numbered cells St Arting 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 is stands on it own in a separate line, and directly followed by a newline. The honey comb numbers are all less than 100 000.

Output specification

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

Sample Input

1
2
3
4
5

Sample Output

0 0
0 1
-1 1
-1 0
0-1

O (1) Complexity of the train of thought: This problem if only look at the map on the left, you will find that each vertical column ordinate the same, and the lower left oblique each column ordinate the same. But this does not identify the relationship between these points, in fact, to change the angle, if the left coordinate in a rectangular coordinate system, it is easier to see that this is a very regular diagram, only need to cross ordinate the addition and subtraction is good, as for the addition and reduction of how much that depends on the number of layers, The number of layers can be calculated according to the general terms of the coordinates on the x-axis.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.