牛客网-101-配比-京东
配比
http://www.nowcoder.com/questionTerminal/290d29b66ca942dbb19f6268025c3727
数学方法,本题通过消元法转换为一元函数,但是编程不好实现,N个约束的转换
编程把每种材料作为最小的哪个,取所有情况最小值
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); double v = scanner.nextDouble(); double[] a = new double[n];//比例 double[] b = new double[n]; //上限 double sum = 0; for(int i = 0; i < n; i++){ a[i] = scanner.nextInt(); sum += a[i]; } for(int i = 0; i < n; i++){ b[i] = scanner.nextInt(); v = Math.min(v, b[i] * sum / a[i]); } System.out.println(String.format("%.4f", v)); } }