POJ 2976 Dropping tests
来源:互联网 发布:上海软件开发培训班 编辑:程序博客网 时间:2024/06/05 18:09
题意:给n组a[i]和b[i],去掉其中的k组,使得剩下的a的总和/b的总和最大
解题思路:最大化平均值.条件是:可以选择使得平均值不小于x,原问题就变成了满足条件的最大的x。接下来就是判断x是否可行,也就是满足式子:a[i]/b[i]>=x,即a[i]-x*b[i]>=0,然后将a[i]-x*b[i]排序贪心的选取后n-k个即可
代码:
#include <iostream>#include <algorithm>#include <cstring>#include <string>#include <cstdio>#include <cmath>using namespace std;#define INF 0x3f3f3f3fconst int maxn=1005;int n,k;int a[maxn],b[maxn];double y[maxn];bool judge(double x){ for(int i=0;i<n;i++) { y[i]=a[i]-x*b[i]; } sort(y,y+n); double sum=0; for(int i=0;i<k;i++) { sum+=y[n-i-1]; } if(sum>=0)return true; return false;}int main(){ while(scanf("%d%d",&n,&k)&&n+k) { k=n-k; for(int i=0;i<n;i++) { scanf("%d",&a[i]); } for(int i=0;i<n;i++) { scanf("%d",&b[i]); } double lb=0,ub=INF; for(int i=0;i<100;i++) { double mid=(lb+ub)/2; if(judge(mid))lb=mid; else ub=mid; } printf("%.0f\n",ub*100); } return 0;}
阅读全文
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分数规划
- Mahout代码示例
- Elasticsearch如何选择索引或类型来存储数据
- 集合_课后练习
- 20170914
- 使用fastjson遇到的一点问题
- POJ 2976 Dropping tests
- 流:文本文件的读写
- django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法
- ajax传参到controller时报400 Bad Request
- 简单ajax交互
- POM文件详解
- day02_java基础加强(jdk新特性 javaa设计模式 反射)
- path环境变量|classpath环境变量
- window配置TensorFlow-gpu版本出现问题