POj 2976
来源:互联网 发布:mac设置自动关机 编辑:程序博客网 时间:2024/06/06 18:49
题目分析:01分数规划
import java.text.DecimalFormat;import java.util.Arrays;import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner scanner = new Scanner(System.in);while(scanner.hasNext()) {int N = scanner.nextInt();int k = scanner.nextInt();if(N == 0 && k ==0) continue;int[] a = new int[N];int[] b = new int[N];for(int i = 0; i < N; i++) {a[i] = scanner.nextInt();}for(int i = 0; i < N; i++) {b[i] = scanner.nextInt();}double L = 0.0;double R = 1.0;double[] f = new double[N];double mid = 0.0;while(Math.abs(L-R) > Math.pow(10, -6)) {mid = (L+R)/2;for(int i = 0; i < N; i++) {f[i] = a[i] * 1.0 - mid * b[i] * 1.0;}Arrays.sort(f);double sum = 0.0;for(int i = k; i < N; i++) {sum += f[i];}//函数是递减的if(sum > 0) {L = mid;} else if(sum < 0) {R = mid;} else break;}mid *= 100;DecimalFormat format = new DecimalFormat("0");System.out.println(format.format(mid));}}}
阅读全文
0 0
- POJ-2976
- POJ 2976
- POj 2976
- 【POJ】2976
- POJ 3104&&POJ 2976 继续二分搜索。。。
- POJ 2976 参数搜索
- poj 2976 Dropping tests
- POJ 2976 Dropping tests
- poj 2976 分数规划
- POJ 2976 Dropping tests
- poj 2976-Dropping tests
- POJ 2976 Dropping tests
- POJ 2976 Dropping tests
- POJ-2976-Dropping tests
- poj 2976 Dropping tests
- POJ 2976 Dropping tests
- Poj 2976 Dropping tests
- poj 2976(二分)
- Python并发速查表
- 初入Python
- 关于linux文件权限的介绍
- Struts2知识点
- Leetcode 514. Freedom Trail
- POj 2976
- 大数据以及Hadoop相关概念介绍
- 苹果系统安装Java开发环境JDK
- 【luogu1052】过河(dp)
- Hibernate 事务提交sql语句的顺序
- Spring Security(09)——Filter
- ~守护进程~
- Java NIO系列教程(一) Java NIO 概述
- 消息驱动