01 Fractional Planning: Make a= (A1,a2,a3,..., an), b= (B1,b2,b3,..., bn), x= (x1,x2,x3,..., xn) are n-dimensional integer vectors, the maximum or minimum value of a*x/b*x, where x[i] can only take 0 or 1, that is to ask (A1*X1+A2*X2+A3*X3+...+AN*XN)/(B1*X1+B2*X2+B3*X3+...+BN*XN), and xi={0,1}, the maximum, x 01 means: If XI takes 1, then Ai,bi will be able to obtain If Xi takes 0,ai and BI is not taken at the same time. This satisfies the topic that the corresponding AI and bi are either taken, or not taken. Can be a two-part answer X,x=ai/bi, get the function f=ai-bi*x, if f>0, you can increase x, if f<0, you can reduce the x.
Import Java.sql.Array;
Import Java.util.Arrays;
Import java.util.Collections;
Import Java.util.Comparator;
Import Java.util.Scanner;
/** * Main * @author FD * @date 2015/11/30 0030 * * public class Main {public static void main (string[] args) {
Scanner Scanner = new Scanner (system.in);
while (Scanner.hasnext ()) {int n = scanner.nextint (), M = Scanner.nextint ();
if (n = = 0 && m = = 0) {break;
} double a[] = new Double[n + 1];
Double b[] = new Double[n + 1];
Double c[] = new Double[n + 1];
for (int i = 1; I <= n; i++) {A[i] = scanner.nextdouble ();
} for (int i = 1; I <= n; i++) {B[i] = scanner.nextdouble ();
} Double L = 0, R = 1, ans = 0;
for (int i = 0; i < i++) {Double mid = (l+r)/2; for (int j = 1; J <= N; j + +){C[j] = a[j]-mid*b[j];
} arrays.sort (c, 1, n+1);
Double tmp = 0;
for (int j = m+1; J <= N; j + +) {tmp + = C[j];
} if (tmp > 0) {l = mid;
} else {r = Mid;
}} System.out.println ((int) (l * 100 + 0.5)); }
}
}