Submit | All submissions | Best solutions | Back to list |
MINCOUNT - Move To Invert |
A triangle made of coins of height h is as follows:
- It has h coins at the base and h-1 coins one level above base and so on. (Coins are placed as shown in the figure below.)
- At the top-most level there will be only one coin.
Now given h, the task is to invert this triangle by moving the minimum number of coins.
For example when h=4 triangle is:
For h=4 at least 3 coins must be moved to invert it.
Input
In the first line N will be given and then N lines follow with each line having a integer which is the height of triangle in that test case. (0 ≤ h < 1010.)
Output
For each test case output in a separate line the minimum number of moves required to invert the triangle. Output fits in long long data type.
Example
Input: 1 3 Output: 2
Added by: | Abhilash I |
Date: | 2006-12-16 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ERL JS-RHINO |
Resource: | IIIT Hyderabad Local Programming Contest |
hide comments
|
||||||||||
2010-08-08 18:27:58 Nathaniel Barshay
Although the problem statement allows for an answer outside of a 64-bit integer, the test cases all fall in the 64-bit range. |
||||||||||
2010-08-04 12:00:10 Curiosa
someone can explain the example in the image? i need 4 moves for h=4 |
||||||||||
2010-04-17 20:34:24 subhadeep maji
nice little math :) |
||||||||||
2010-04-07 05:05:36 :(){ :|: & };:
I wonder if there is any programmatic solution for this task, since all I used is simple math. |
||||||||||
2010-03-21 18:53:56 vimal raj sharma old account
@Sergey Ushacov how are u saying that correct ans. for 10000000000 is 7 443 294 631 478 557 525 i think that "dreivaj (Slash at the moment)"'s solution is right mine is also giving the same :) |
||||||||||
2010-03-12 06:33:04 Zubaidullo
yehhhh. I have AC. (i use STADIO.H with float) |
||||||||||
2010-02-14 14:32:08 Core2Duo
The test cases dont seem to be having inputs till 10^10. The correct ans for 10^10 cannot b stored in long long int in C++, still I get AC! |
||||||||||
2010-01-26 13:19:22 ☻Daniel Alberti Proenza☻
What is the correct answer for h = 10 and h = 11? |
||||||||||
2010-01-20 07:55:31 Super Lại Mạnh Tuấn
What is the correct answer for h=6 and h=7 ? Last edit: 2010-01-20 08:05:41 |
||||||||||
2009-10-07 18:04:36 Sergey Ushacov
The correct answer for h = 10000000000 is 7 443 294 631 478 557 525 |