Continuing with my said goal ( solving 5 problems per day) This is what I did for the 2 days…
I have planned to put 5 problems of the GCJ types and discuss post and lot picked one for the next 2 weeks until July 10th.
So the list of problems that were chosen the last 2 days were:
- Akhil and colored balls
- Kitchen Time Table
- Chef And Way
- Alternating sub-array prefix
- Simple Statistics
- Palindrome Substrings
- Chef and Coloring
- Movie Weekend
- Coins and Triangle
Chef belongs to a very rich family which owns many gold mines. Today, he brought N gold coins and decided to form a triangle using these coins. Isn’t it strange?
Chef has an unusual way of forming a triangle using gold coins, which is described as follows:
He puts 1 coin in the 1st row.
then puts 2 coins in the 2nd row.
then puts 3 coins in the 3rd row.
The chef is interested in forming a triangle with maximum possible height using at most N coins. Can you tell him the maximum possible height of the triangle?
The first line of input contains a single integer T denoting the number of test cases.
The first and the only line of each test case contains an integer N denoting the number of gold coins Chef has.
For each test case, output a single line containing an integer corresponding to the maximum possible height of the triangle that Chef can get.
1 = T = 100
1 = N = 109
Test 1: Chef can’t form a triangle with height > 2 as it requires at least 6 gold coins.
Test 2: Chef can’t form a triangle with height > 2 as it requires at least 6 gold coins.
Test 3: Chef can’t form a triangle with height > 3 as it requires at least 10 gold coins.
T = int(input());
for i in range(T):
n = int(input());
int h = 1;
while((h * (h+1) / 2) <= n):
But I wasn’t satisfied…the answer was too direct for my liking so I was twisting the code to my liking?
So the code I came up with is this… pretty simple, right?
n = [int(input()) for i in range(t)]
for i in n:
height = triangle_height(i)
height = 1
coins = 1
inc = 2
while coins < n_coin:
coins += inc
if coins > n_coin:
inc += 1
height += 1