변경이력

돌아가기
2 12개 문자 추가 28개 문자 삭제

2016/10/21 05:08

권용훈

**Ruby** ```{.ruby} def min_times nwl,(_,w,l), trucks = (1..2).map {gets.split.map &:to_i}; _,w,l = *nwl add = ->b,c,t { b.shift; b.reduce(:+)sum <= l-t ? [b<<t, c+1] : add[b<<0, c+1, t] } puts trucks.reduce([[0]*w,0]) {|a,truck| add[*a,truck] }[1] + w end ``` **Test** ```{.ruby} # stdin datas case1 = "4 2 10\n7 4 5 6\n" case2 = "1 100 100\n10\n" case3 = "10 100 100\n10 10 10 10 10 10 10 10 10 10\n" $stdin = StringIO.new(case1 + case2 + case3) expect{ min_times }.to output("8\n").to_stdout # case 1 expect{ min_times }.to output("101\n").to_stdout # case 2 expect{ min_times }.to output("110\n").to_stdout # case 3 ``` **Output** ```{.ruby} min_times 11 2 10 7 4 5 6 1 4 2 3 5 7 4 17 ```
**Ruby** ```{.ruby} def min_times nwl,(_,w,l), trucks = (1..2).map {gets.split.map &:to_i}; _,w,l = *nwl add = ->b,c,t { b.shift; b.reduce(:+)sum <= l-t ? [b<<t, c+1] : add[b<<0, c+1, t] } puts trucks.reduce([[0]*w,0]) {|a,truck| add[*a,truck] }[1] + w end ``` **Test** ```{.ruby} # stdin datas case1 = "4 2 10\n7 4 5 6\n" case2 = "1 100 100\n10\n" case3 = "10 100 100\n10 10 10 10 10 10 10 10 10 10\n" $stdin = StringIO.new(case1 + case2 + case3) expect{ min_times }.to output("8\n").to_stdout # case 1 expect{ min_times }.to output("101\n").to_stdout # case 2 expect{ min_times }.to output("110\n").to_stdout # case 3 ``` **Output** ```{.ruby} min_times 11 2 10 7 4 5 6 1 4 2 3 5 7 4 17 ```
1 Original

2016/10/12 22:24

권용훈

코딩도장

코딩도장은 프로그래밍 문제풀이를 통해서 코딩 실력을 수련(Practice)하는 곳입니다.