poj2976 Dropping tests
01分数规划裸题
为毛二分一定要打成r=mid这么恶心啊
#include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> using namespace std; typedef long long LL; int n,k; double a[1100],b[1100],c[1100]; double check(double mid) { for(int i=1;i<=n;i++)c[i]=a[i]-mid*b[i]; sort(c+1,c+n+1); double ret=0; for(int i=n;i>k;i--)ret+=c[i]; return ret; } int main() { while(scanf("%d%d",&n,&k)!=EOF) { if(n==0&&k==0)break; for(int i=1;i<=n;i++)scanf("%lf",&a[i]); for(int i=1;i<=n;i++)scanf("%lf",&b[i]); double l=0,r=1,ans; while(r-l>1e-8) { double mid=(l+r)/2; if(check(mid)>0) { l=mid; } else r=mid; } printf("%.0lf\n",r*100); } return 0; }
pain and happy in the cruel world.