POJ 2976 Dropping tests 01分数规划

很简单的01分数规划问题 二分答案即可 由于a[i] <= b[i] 所以上界一定小于等于1

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)

const int maxn = 1000 + 10;
const double eps = 1e-8;

int n, k;
double a[maxn], b[maxn], c[maxn];

void solve(){
          REP(i, 0, n) scanf("%lf", &a[i]);
          REP(i, 0, n) scanf("%lf", &b[i]);
          double l = 0, r = 1, sum, m;
          while(l + eps < r){
                    m = (l + r) / 2;
                    sum = 0;
                    REP(i, 0, n) c[i] = a[i] - m * b[i];
                    sort(c, c + n);
                    REP(i, k, n) sum += c[i];
                    if(sum > eps) l = m;
                    else r = m;
          }
          printf("%d\n", int(l * 100 + 0.5));
}

int main()
{
          while(~scanf("%d%d", &n, &k) && n) solve();
          return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值