题目大意:n个二元组a[i],b[i],去掉k个,求sigma a[i]/ sigma b[i]的最大值
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define N 1009 #define LL long long using namespace std; LL n,k; LL a[N],b[N]; double c[N]; inline int read() { register LL x=0,f=1;register char ch=getchar(); while(ch<'0'||ch>'9') if(ch=='-') f=-1,ch=getchar(); while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*f; } int main() { while(1) { n=read();k=read(); if(!n&&!k) break; for(int i=1;i<=n;i++) a[i]=read(); for(int i=1;i<=n;i++) b[i]=read(); double l=0,r=100; while(r-l>1e-5) { double mid=(l+r)/2,p=0; for(int i=1;i<=n;i++) c[i]=a[i]-mid*b[i]; sort(c+1,c+n+1); for(int i=n;i>=k+1;i--) p=p+c[i]; if(p>=0) l=mid; else r=mid; } printf("%.0f\n",l*100); } return 0; }