UVa1648 - Business Center

出處:https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=4523

解題策略:

假設向上按x次,向下按y次

x+y = n

求 x*u - y*d 最小值,y=n-x代入

x*u-(n-x)*d= x*(u+d) - n*d,使用二分搜尋列舉x,求x*(u+d) - n*d大於0的最小值

程式碼