Test instructions
There's a strange elevator that can only walk up the U-floor or down D-floors at a time.
Now there are M elevators, the minimum number of floors (which must be positive) to arrive at exactly N times, and the first default is on the No. 0 floor.
Analysis:
Assuming that the elevator goes up x times, then go down n-x times, then reach the floor is Xu-(n-x) d≥0
(u+d) The minimum value for the x≥nd,x is
In other words, if nd% (u+d) = = 0, x = nd/(u+d)
otherwise x = nd/(u+d) + 1
Considering that the condition cannot be reached on the 0 floor: when nd% (u+d) = = 0 This happens, you can only have one more time on the U-level, less the next D-floor, so this will eventually stop at the U+D layer
1#include <cstdio>2 3 intMain ()4 {5 intN, M;6 7 while(SCANF ("%d%d", &n, &m) = =2)8 {9 intAns =1000000000;Ten while(m--) One { A intu, D; -scanf"%d%d", &u, &d); - if((n*d)% (u+d) = =0) {if(U+d < ans) ans = u+D;} the Else - { - intx = (n*d)/(U+D) +1; - intt = x* (u+d)-n*D; + if(T < ans) ans =T; - } + } Aprintf"%d\n", ans); at } - - return 0; -}
code June
UVa 1648 (push formula) business Center