poj 2976 基础01分数规划
生活随笔
收集整理的這篇文章主要介紹了
poj 2976 基础01分数规划
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
這個題算是01分數(shù)規(guī)劃的最基本的應用了, 01分數(shù)規(guī)劃是給你n對數(shù)(a1, b1)....(an, bn), 然后讓你選擇一些數(shù)對, 使得sigma(ai)/sigma(bi)最大。這里附上講解一份,?http://blog.csdn.net/hhaile/article/details/8883652, 代碼如下:
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <cmath>using namespace std; typedef long long LL; const int maxn = 1000 + 10; const double eps = 1e-4; int n, k; double ai[maxn], bi[maxn]; double ci[maxn];double check(double mid) {for(int i=0; i<n; i++) ci[i] = ai[i]*100 - mid*bi[i];sort(ci, ci+n);double res = 0.0;for(int i=k; i<n; i++) res += ci[i];return res; }int main() {while(cin>>n>>k){if(n==0 && k==0) break;for(int i=0; i<n; i++) scanf("%lf", &ai[i]);for(int i=0; i<n; i++) scanf("%lf", &bi[i]);double l=0.0, r=100;double ans;while(r-l > eps){double mid = (l+r)/2;if(check(mid) >= -eps) l=ans=mid;else r=mid;}printf("%.0f\n", ans);}return 0; }?
轉(zhuǎn)載于:https://www.cnblogs.com/xingxing1024/p/5224717.html
總結
以上是生活随笔為你收集整理的poj 2976 基础01分数规划的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦到被巨蛇追着跑预示着什么
- 下一篇: bootstrap基础学习十篇