11633 - Food portion sizes
Posted: Sat Sep 05, 2009 11:53 am
can anyone help me how to solve this problem? i have thought of a solution like this:
S=ax+by
let the food portion size if u
for first person,
i1=amount he needs
x1= amount wasted
y1=how many times he goes to fetch food
x1=u*ceil(i1/u)-i1
y1=ceil(i1/u)
s1=ax1+by1=(au+b)*ceil(i1/u)-a*i1
similarly
s2=(au+b)*ceil(i2/u)-a*i2
s3=(au+b)*ceil(i3/u)-a*i3
.......
S=S1+S2+.....
=(au+b)*(ceil(i1/u)+ceil(i2/u)+ceil(i3/u)+...)-a*(i1+i2+i3+.....)
now S is the ans
we can determine u to get S minimum.(y<=3) but u has to be very accurate so that it can be turned into fractoin (x/y form) brute force will make TLE.
am i correct?
so any idea how to solve this?
S=ax+by
let the food portion size if u
for first person,
i1=amount he needs
x1= amount wasted
y1=how many times he goes to fetch food
x1=u*ceil(i1/u)-i1
y1=ceil(i1/u)
s1=ax1+by1=(au+b)*ceil(i1/u)-a*i1
similarly
s2=(au+b)*ceil(i2/u)-a*i2
s3=(au+b)*ceil(i3/u)-a*i3
.......
S=S1+S2+.....
=(au+b)*(ceil(i1/u)+ceil(i2/u)+ceil(i3/u)+...)-a*(i1+i2+i3+.....)
now S is the ans
we can determine u to get S minimum.(y<=3) but u has to be very accurate so that it can be turned into fractoin (x/y form) brute force will make TLE.
am i correct?
so any idea how to solve this?