【请教】有人用gas的dryer吗?# PennySaver - 省钱一族
f*n
1 楼
The problem is "Minimum number of moves to make an integer array balance".
Move is defined as reducing one element in array and increase anther integer
.
Balance is defined as the maximum difference between two integers in whole
array is 1.
lo=floor(average of array x)
up=ceil(average of array x)
lo_sum =the sum of all (lo - x[i]) for each x[i] up_sum=the sum of all (x[i]-up) for each x[i]>up
My solution is max(lo_sum, up_sum)
Here are several examples with my solution going through.
[1 2 3] with lo=up=2 max(2-x[0], x[2]-2)=1 correct
[4 1 3 2] with average=9/4=2 lo=2 up=3 max(2-x[1], x[0]-3)=1 correct
[5 100 2 0 3] output 78 to get [22 22 22 22]
with average=22 lo=up=22 max(22-5+22-2+22-0+22-3, 100-22)=78
[1 4 4 4 4 4 4] should output 2
with average=25/7=3 lo=3 up=4
max(3-1, 0)=2 also correct
请问这个解法有啥问题吗?
Move is defined as reducing one element in array and increase anther integer
.
Balance is defined as the maximum difference between two integers in whole
array is 1.
lo=floor(average of array x)
up=ceil(average of array x)
lo_sum =the sum of all (lo - x[i]) for each x[i]
My solution is max(lo_sum, up_sum)
Here are several examples with my solution going through.
[1 2 3] with lo=up=2 max(2-x[0], x[2]-2)=1 correct
[4 1 3 2] with average=9/4=2 lo=2 up=3 max(2-x[1], x[0]-3)=1 correct
[5 100 2 0 3] output 78 to get [22 22 22 22]
with average=22 lo=up=22 max(22-5+22-2+22-0+22-3, 100-22)=78
[1 4 4 4 4 4 4] should output 2
with average=25/7=3 lo=3 up=4
max(3-1, 0)=2 also correct
请问这个解法有啥问题吗?