日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

POJ 2976 Dropping tests【二分 最大化平均值】

發布時間:2025/4/16 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ 2976 Dropping tests【二分 最大化平均值】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:定義最大平均分為 (a1+a2+a3+---+an)/(b1+b2+---+bn),求任意去除k場考試的最大平均成績

和挑戰程序設計上面的最大化平均值的例子一樣

判斷是否存在x滿足條件 (a1+a2+a3+---+an)/(b1+b2+---+bn)>=x

把這個不等式變形就得到

E(ai-x*bi )>=0

所以可以對ai-x*bi降序排序,取前n-k個,看它們的和是不是>=0(或者升序排,取后n-k個)

后來搜題解發現是01分數規劃,列的式子好像都差不多-------

1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<stack> 6 #include<vector> 7 #include<map> 8 #include<set> 9 #include<queue> 10 #include<algorithm> 11 using namespace std; 12 13 typedef long long LL; 14 const int INF = (1<<30)-1; 15 const int mod=1000000007; 16 const int maxn=10005; 17 18 double a[maxn],b[maxn],y[maxn]; 19 int n,k; 20 21 22 int ok( double x){ 23 for(int i=1;i<=n;i++) y[i]= a[i]-b[i]*x; 24 sort(y+1,y+n+1); 25 double ans=0; 26 for(int i= k+1;i<=n;i++) ans+=y[i]; 27 28 return ans>=0; 29 } 30 31 int main(){ 32 while(scanf("%d %d",&n,&k)!=EOF){ 33 if(n==0&&k==0) break; 34 for(int i=1;i<=n;i++) scanf("%lf",&a[i]); 35 for(int i=1;i<=n;i++) scanf("%lf",&b[i]); 36 37 double lb=0,ub=1.00,mid; 38 for(int i=0;i< 100;i++){ 39 mid=(lb+ub)/2; 40 if(ok(mid)) lb=mid; 41 else ub=mid; 42 } 43 printf("%d\n",(int)(100*lb+0.5)); 44 } 45 return 0; 46 } View Code

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?好餓~~(╯﹏╰)b

加油啊---------------goooooooooo----------

?

轉載于:https://www.cnblogs.com/wuyuewoniu/p/4578747.html

總結

以上是生活随笔為你收集整理的POJ 2976 Dropping tests【二分 最大化平均值】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。