POJ 2976 Dropping tests 01 fractional programming method

Source: Internet
Author: User
Tags arrays
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)); }
    }
}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.