http://poj.org/problem?id=2976
2.Idea
Binary Search
3.Source
int N, K;
int a[1003];
int b[1003];
double y[1003];
bool C(double x)
{
for (int i = 0; i < N; i++) {
y[i] = (double)a[i] - x * (double)b[i];
}
sort(y, y + N);
double sum = 0.0;
for (int i = K; i < N; i++) sum += y[i];
return sum >= 0;
}
void solve()
{
double l = 0.0, r = 1.0;
for (int i = 0; i < 100; i++) {
double m = (l + r) * 0.5;
if (C(m)) {
l = m;
}
else {
r = m;
}
}
cout << (int)(100.0 * l + 0.5) << endl;
}
int main()
{
while (scanf("%d%d", &N, &K) > 0) {
if (N + K == 0) break;
for (int i = 0; i < N; i++) cin >> a[i];
for (int i = 0; i < N; i++) cin >> b[i];
solve();
}
return 0;
}
No comments:
Post a Comment