题目链接:
很典型的01分数规划,sort+二分即可。注意精度问题,这种四舍五入的问题一般都是两种处理方法:1、printf("%.0lf\n",ans); 2、printf("%d\n",(int)(ans+0.5));
1 //STATUS:C++_AC_47MS_196KB 2 #include3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 using namespace std;13 #define LL __int6414 #define pii pair 15 #define Max(a,b) ((a)>(b)?(a):(b))16 #define Min(a,b) ((a)<(b)?(a):(b))17 #define mem(a,b) memset(a,b,sizeof(a))18 #define lson l,mid,rt<<119 #define rson mid+1,r,rt<<1|120 const int N=1010,M=1000000,INF=0x3f3f3f3f,MOD=1999997;21 const LL LLNF=0x3f3f3f3f3f3f3f3fLL;22 const double DNF=100000000;23 24 double d[N];25 int a[N],b[N];26 int n,k;27 28 double binary()29 {30 int i;31 double l=0,r=1,mid,s;32 while(r-l>1e-4){33 mid=l+(r-l)/2;34 for(i=0;i =k;i--)s+=d[i];37 if(s>0)l=mid;38 else r=mid;39 }40 return mid;41 }42 43 int main()44 {45 // freopen("in.txt","r",stdin);46 int i,j;47 while(~scanf("%d%d",&n,&k) && (n||k))48 {49 for(i=0;i