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
hide comments
PRIBAN91:
2015-06-09 08:29:44
Getting lots of TLE in Java. Any suggestion will be appreciated. |
|
Ankit Aggarwal :
2014-10-17 19:50:38
http://discuss.codechef.com/questions/50378/spoj-mincount-wa
|
|
Mahesh Mishra:
2014-10-17 08:37:51
Test Cases are weak.. |
|
pvkcse:
2014-08-16 21:28:26
As like others,same algo in python got TLE while in C AC with 14 lines...It is the shortest C code written in Spoj by me... |
|
Ayush Vatsa:
2014-06-16 09:29:26
Move to challenge |
|
sarelfeniel:
2014-04-03 06:34:47
Nice problem! Learnt something about how to cleverly avoid overflow errors. |
|
mockingjay:
2014-03-09 18:47:46
it seems that 10^10 is not in test cases
|
|
NoName:
2013-12-12 10:59:05
at last got AC after a lots of TLE...if using c++ then use scanf and printf instead of cin and cout...this shows that scanf and printf are really faster...
|
|
Raman Shukla:
2013-08-01 12:40:30
Simple O(1) solution... Solve for small cases to get the answer... |
|
mystique_blue:
2013-04-05 06:29:41
Move to challenge. |
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 |