题目大意
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/26a7b276f22e096240a427746f37cdea.png)
解题思路
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/d72b1f2a6ddfc04382c09acac0917dc7.png)
代码
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<stdio.h>
using namespace std;
const int MAXN = 10000+5;
struct Node
{
double v, w;
double b;
bool operator < (const Node& A) const
{
return v-b*w > A.v - A.b*A.w;
}
}tools[MAXN];
int main()
{
int k, n;
while(scanf("%d%d",&n, &k))
{
if(n == 0 && k == 0)
break;
k = n-k;
for(int i=0; i<n; i++)
scanf("%lf",&tools[i].v);
for(int i=0; i<n; i++)
scanf("%lf",&tools[i].w);
double l = 0;
double r = 1000000000.2;
while(r-l>=0.0001)
{
double mid = (l+r)/2;
for(int i=0; i<n; i++)
tools[i].b = mid;
sort(tools, tools+n);
double thread = 0;
for(int i=0; i<k; i++)
{
thread += tools[i].v - tools[i].b * tools[i].w;
}
if(thread >= 0)
l = mid;
else
r = mid;
}
printf("%d\n", (int)round(l * 100));
}
return 0;
}
知识点
round()
函数用来四舍五入。scanf("lf", &f)
用来输入double