2019年4月25日 星期四

[UVa][ Volume I ] 102 - Ecological Bin Packing

[UVa][ Volume I ] 102 - Ecological Bin Packing



題目來源 : Ecological Bin Packing


解題 :


一開始想法是 :
先找出這9個數字的最大值,再找出被選擇的顏色與桶子中的最大值
接著同樣找出未被選擇的顏色與桶子中的最大值
然後瓶子總和減掉這三個數字就是移動的最小值了。

不過後來再看一次題目Output敘述以及顏色順序是B-G-C,顯然這個方法行不通,因為最後一定會出現順序錯誤的問題
"If more than one order of brown, green, and clear bins yields the minimum number of movements then the alphabetically first string representing a minimal configuration should be printed. "

後來更改想法,直接根據顏色順序來選。也就是說,直接照個字母順序
先選Clear要使用哪個桶子,再選Brown要使用哪個桶子,最後那個桶子就是Green的

此題使用暴力法求出所有可能,再得到裡面最小值。由於已經是依照字母順序選擇,所以即便出現相同的最小值,則後得到的字典順序也會小於先得到的。


參考解答(C++)


沒有留言:

張貼留言