题目大意:
题解:
裸的01分数规划
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
const int maxn = 1024;
const double eps = 1e-9;
inline int dcmp(const double &x){
if(x < eps && x > -eps) return 0;
return x > 0 ? 1 : -1;
}
int a[maxn],b[maxn];
double d[maxn];
int main(){
int n,m;
while(1){
read(n);read(m);m = n - m;
if(n == 0 && m == 0) break;
for(int i=1;i<=n;++i) read(a[i]);
double l = 0,r = 0;
for(int i=1;i<=n;++i){
read(b[i]);
r = max(r,(double)a[i]/b[i]);
}
while((r-l) > eps){
double mid = (l+r)/2;
for(int i=1;i<=n;++i) d[i] = a[i] - mid*b[i];
sort(d+1,d+n+1);double sum = 0;
for(int i=n;i>=n-m+1;--i) sum += d[i];
if(dcmp(sum) >= 1) l = mid;
else r = mid;
}
printf("%d
",(int)(l*100.0 + 0.5) );
}
getchar();getchar();
return 0;
}