POJ - 2976

分析

找来的 分数规划模板题。我们要求的是 ,所以直接二分 ,那么贪心的选取最大的 ,最后再判断 就好了。

代码

// #include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define LL long long
using namespace std;
LL read() {
    LL x = 0,f = 0;char ch = getchar();
    while(!isdigit(ch)) {if(ch == '-')f=1;ch=getchar();}
    while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();}
    return f?-x:x;
}
LL n,m;
const int N = 1e4 + 100;
LL a[N],b[N];
const double inf = 2e18;
double c[N];
bool check(double mid) {
    for(int i = 1;i <= n;i++) c[i] = a[i] - mid * b[i];
    sort(c+1,c+1+n);double ans = 0;
    for(int i = n;i >= m+1;i--) ans += c[i];
    return ans > 0 ;
}
int main() {
    while(1) {
        n = read();m = read();
        if(!n && !m) break;
        for(LL i = 1;i <= n;i++) a[i] = read() * 100LL;
        for(LL i = 1;i <= n;i++) b[i] = read();
        double l = -inf,r = inf;
        while(r - l > 1e-10) {
            double mid = (l + r) / 2;
            if(check(mid)) l = mid;
            else r = mid;
        }
        printf("%lld\n",(LL)(l+0.5));
    }
    return 0;
}
全部评论

相关推荐

ohs的小木屋:比不少实习待遇高了
点赞 评论 收藏
分享
07-01 17:14
中北大学 Java
兄弟们是真是假
牛客46374834...:我在boss上投java岗从来没成功过
点赞 评论 收藏
分享
07-03 11:02
中山大学 C++
字节刚oc,但距离九月秋招很近了有两段互联网实习,非腾讯字节。不敢赌转正,现在在纠结去还是不去如果实习俩月离职会有什么后果吗
阿城我会做到的:不去后悔一辈子,能否转正取决于ld的态度,只要他不卡,答辩就是走流程,个人觉得可以冲一把
投递字节跳动等公司8个岗位
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务