计算卡车货运能力在一场比赛中 [英] Calculating truck cargo capacity in a game
问题描述
这更多的是一个数学/算法的问题不是一个编程问题,但我希望你们能帮忙呢。
情景1:
播放机1 40
箱
在他的库存。播放机1 2
车
,1个
小
(容量:8箱)1个
中
(容量:16箱)
由于
容量
:A
小
卡车能装8箱A
中
卡车能装16箱A
大
卡车能装30箱
多少车没有播放器1需要能够采取所有40箱?
情景2,如果有货物已在卡车发生什么呢?
玩家1有40个包装箱及2卡车上面的场景。
如果
小
已经有2箱在其负荷,给他8-2 = 6的空间如果
中
已经有4个箱子中的负载,让他16-4 = 8的空间多少车没有播放器1需要采取所有40个箱子?什么算法呢?
情景3:无车
播放机1 0卡车在所有。有多少车他需要采取所有40箱?此外,什么是你可以使用algoritm?
情景#4:有太多的车
播放机1 10辆卡车,全部
大
的能力。有多少车没有考虑到船舶上的所有40箱?
我的想法。
情景1,
2辆卡车,1小= 8和1个中等大小= 16
8 + 16 = 24箱
40 - 24 = 16辆卡车? //这看起来是错误的。
卡车的成本都在早些时候完成(你先买)。
我觉得我的算法是错误的。我需要一个基数来划分呢?难道我把它用卡车?
在这个任何帮助将是非常有益的。
我建议以下算法(伪code)
做卡车= 1,number_trucks
current_capacity(卡车)= total_capacity(卡车) - loaded_crates(卡车)
ENDDO
根据current_capacity排序卡车(大前)
remaining_crates = 40
办卡= 1,number_trucks
如果(remaining_crates - current_capacity(卡车)大于0)
载货车全
remaining_crates - = current_capacity(卡车)
其他
如果(卡车!=上车)
如果(remaining_crates - current_capacity(卡车+ 1)0)
与remaining_crates载货车
remaining_crates = 0
ENDIF
其他
载货车全
remaining_crates - = current_capacity(卡车)
ENDIF
ENDIF
ENDDO
根据total_capacity(truck_class)(最大的开始)按truck_class
DO truck_class = 1,number_truck_classes
而(remaining_crates - total_capacity(truck_class)大于0)
买truck_class卡车
remaining_crates - = total_capacity(truck_class)
端,而
如果(truck_class == number_truck_classes&安培;&安培; remaining_crates大于0)
买truck_class卡车
ENDIF
ENDDO
This is more of a math/algorithm question than a programming question, but I hope you guys can help anyway.
Scenario #1:
Player 1 has 40
crates
in his inventory.Player 1 has 2
trucks
,1x
small
(capacity: 8 crates)1x
medium
(capacity: 16 crates)
Given
capacity
:A
small
truck can hold 8 cratesA
medium
truck can hold 16 cratesA
large
truck can hold 30 crates
How many trucks does player 1 need to be able to take all 40 crates?
Scenario #2, what happens if there is cargo already in trucks?
Player 1 has 40 crates and 2 trucks as above scenario.
If
small
already has 2 crates in its load, giving him 8-2 = 6 spaceIf
medium
already has 4 crates in its load, giving him 16-4 = 8 spaceHow many trucks does player 1 need to take all 40 crates? What would the algorithm be?
Scenario #3: No trucks
Player 1 has 0 trucks at all. How many trucks does he need to take all 40 crates? Again, what is the algoritm you would use?
Scenario #4: Too many trucks
Player 1 has 10 trucks, all at
large
capacity. How many trucks does it take to ship all 40 crates?
I'm thinking.
Scenario 1,
2 trucks, 1 small = 8 and 1 medium = 16
8+16 = 24 crates
40 - 24 = 16 trucks?? // This looks wrong.
Costs of trucks are done earlier on (you buy them first).
I think my algorithm is wrong. Do I need to divide it by a base number? Do I divide it by trucks?
Any help on this would be very helpful.
I suggest the following algorithm (in pseudocode)
do truck = 1,number_trucks
current_capacity(truck) = total_capacity(truck) - loaded_crates(truck)
enddo
sort trucks according to current_capacity (biggest first)
remaining_crates = 40
do truck = 1,number_trucks
if(remaining_crates - current_capacity(truck) > 0)
load truck full
remaining_crates -= current_capacity(truck)
else
if(truck != last truck)
if(remaining_crates - current_capacity(truck+1) > 0)
load truck with remaining_crates
remaining_crates = 0
endif
else
load truck full
remaining_crates -= current_capacity(truck)
endif
endif
enddo
sort truck_class according to total_capacity(truck_class) (biggest first)
do truck_class = 1,number_truck_classes
while(remaining_crates - total_capacity(truck_class) > 0)
buy truck of truck_class
remaining_crates -= total_capacity(truck_class)
end while
if(truck_class == number_truck_classes && remaining_crates > 0)
buy truck of truck_class
endif
enddo
这篇关于计算卡车货运能力在一场比赛中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!