2018暑假牛客多校第五场 A题 gpa

  • 题目描述: Kanade selected n courses in the university. The academic credit of the i-th course is s[i] and the score of
    Now she can delete at most k courses and she want to know what the highest final score that can get.

the i-th course is c[i].At the university where she attended, the final score of her is

  • 输入描述:

The first line has two positive integers n,k
The second line has n positive integers s[i]
The third line has n positive integers c[i]

  • 输出描述:

Output the highest final score, your answer is correct if and only if the absolute error with the standard
answer is no more than 10 -5

  • 备注

1≤ n≤ 10 5
0≤ k < n
1≤ s[i],c[i] ≤ 10 3

  • 示例1:

输入
3 1
1 2 3
3 2 1

输出
2.33333333333
说明
Delete the third course and the final score is

题意:给定一个n和k,然后输入s[i]和c[i],求在n组数据中

的最大值,可以删除最多k组数。

解析:主要使用到了01分数规划的相关算法,具体请参考另一位博主的博客01分数规划的问题模型1

由题意可得出函数 f(r)=∑s[i]*c[i]-r*∑s[i];要使f(r)达到最大,可以采用二分法的模板。

#include 
#include 
#include 
#include 
#define eps 1e-11//精确度
using namespace std;
typedef struct node
{
    int a,b;
    double r;
} node;
bool op(node a,node b)
{
    return a.r>b.r;
}
node p[100010];
int main()
{
    int n,k;
scanf("%d%d",&n,&k);

    for (int i=1;i<=n;i++) scanf("%d",&p[i].a);
        for (int i=1;i<=n;i++) scanf("%d",&p[i].b);
        int m=n-k;
        double left=0,right=10000;
        while (left+eps0)
                temp+=p[i].r;
            if (temp>0) left=mid;
            else right=mid;
        }
        printf("%.11f\n",left);
    return 0;
}

 

你可能感兴趣的:(2018暑假牛客多校第五场 A题 gpa)