forked from Nearsoft/google-code-jam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
approach3.rb
57 lines (44 loc) · 995 Bytes
/
approach3.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def waiter(diners, pancakes_array, test_case)
mins_array = []
max = pancakes_array.max
mins_array[0] = max
i = 1
loop do
split = 0
pancakes_array.each do |pancake|
if pancake > i
v = pancake.to_f / i
split = split + (v.ceil - 1)
end
end
mins_array[i] = split + i
if i > 1000
break
end
i = i + 1
end
min = mins_array.min
output = 'Case #' + "#{test_case}: #{min}\n"
print "#{output}\n"
open("./small_dataset.out", "a") do |f|
f.puts output
end
end
File.open("./B-small-practice.in", "r") do |f|
f.each_with_index do |line, index|
if index == 0
next
end
if index % 2 != 0
next
end
if index % 2 == 0
string_arr = line.split(" ")
pancakes_array = string_arr.each.map { |x| x.to_i }
diners = pancakes_array.length
test_case = index / 2
print "Test case #{test_case}\n"
waiter(diners, pancakes_array, test_case)
end
end
end