官方的解题报告可以看这里http://poj.org/showmessage?message_id=53194
我们可以看看如下推导
题目就变成了二分检索r
/******************************************************************************* # Author : Neo Fung # Email : [email protected] # Last modified: 2012-06-10 10:19 # Filename: ZOJ3068 POJ2976 Dropping tests.cpp # Description : ******************************************************************************/ #ifdef _MSC_VER #define DEBUG #define _CRT_SECURE_NO_DEPRECATE #endif #include <fstream> #include <stdio.h> #include <iostream> #include <string.h> #include <string> #include <limits.h> #include <algorithm> #include <math.h> #include <numeric> #include <functional> #include <ctype.h> using namespace std; const int kMAX=10010; const double kEPS=10E-5; int main(void) { #ifdef DEBUG freopen("../stdin.txt","r",stdin); freopen("../stdout.txt","w",stdout); #endif int n,m,ncase=1; double num[kMAX],den[kMAX],scores[kMAX]; while(~scanf("%d%d",&n,&m) && (m+n)) { for(int i=0;i<n;++i) scanf("%lf",&num[i]); for(int i=0;i<n;++i) scanf("%lf",&den[i]); double lhs=0,rhs=1.0; while(lhs+kEPS<rhs) { double x=(lhs+rhs)/2; for(int i=0;i<n;++i) scores[i]=num[i]-den[i]*x; sort(scores,scores+n); double total=0.0; for(int i=m;i<n;++i) total+=scores[i]; if(total>=0.0) lhs=x; else rhs=x; } printf("%d\n",int(100*lhs+0.5)); } return 0; }