POJ 2976 Dropping tests
来源:互联网 发布:全国68所网络教育 编辑:程序博客网 时间:2024/06/05 19:56
POJ 2976 Dropping tests
题意:给定n组数据,取其中k组数据,求最大的平均值,平均值为.
思路:假设我们选了其中的k组数据,那么它们的单位值是∑ai/∑bi,接着可以变成判断是否存在k/满足条件:∑ai/∑bi≥x,变形不等式为∑(ai-x*bi)≥0。
因此可以对(ai-x*bi)的值进行排序贪心地进行选取。因此就变成了C(x)=((ai-x*bi)从大到小排列中的前k个的和不小于0)
对x值进行二分,在0到1之间取值。
AC代码:
import java.util.Arrays;import java.util.Scanner;public class Main{static Scanner scan=new Scanner(System.in);public static void main(String[] args){while(scan.hasNext()){int n=scan.nextInt(),k=scan.nextInt();if(n==0 && k==0) break;int a[]=new int[n],b[]=new int[n];for(int i=0;i<n;i++) a[i]=scan.nextInt();for(int i=0;i<n;i++) b[i]=scan.nextInt();double c[]=new double[n];double l=0,r=1,mid=(l+r)/2,eps=1e-4,sum=0;for(;r-l>eps;mid=(l+r)/2){for(int i=0;i<n;i++) c[i]=a[i]-mid*b[i];Arrays.sort(c);sum=0;for(int i=k;i<n;i++) sum+=c[i];if(sum>=0) l=mid;else r=mid;}System.out.println(Math.round(mid*100));}}}
0 0
- 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 Dropping tests
- Poj 2976 Dropping tests
- POJ-2976Dropping tests
- POJ 2976 Dropping tests
- POJ 2976 Dropping tests
- POJ 2976 Dropping tests
- Dropping tests - POJ 2976 二分
- poj 2976 Dropping tests,二分
- POJ 2976 Dropping tests 01分数规划
- POJ 2976 Dropping tests 01分数规划
- Format the array with hashes
- Linux-6.5下 基于cmake28来编译安装mysql服务配置解析
- 法国企业不甘寂寞 云计算时代都在玩兼并
- 74LS138 解码器 【数字电路】
- 自考身边的例子(一)
- POJ 2976 Dropping tests
- 最感人的10段话,哪段感动了你?
- 【DFS+题意】#24 A. Ring road
- \r和\n在C语言中的区别
- QQ安装,安装路径无效,您没有权限在此位置写入数据,请重新选择
- Windows 8.1 JDK环境变量配置
- 数据库操作中为什么要采用外连接
- 黑马程序员_OC核心语法之分类
- RedHat平台下pureftpd搭建