01 分数规划 poj 2976 利用二分法即可
2013-05-20 16:43
337 查看
#include<iostream> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int maxn = 1005; double a[maxn],b[maxn],c[maxn]; int m,n,k; double L,R,mid; bool big(double p){ for(int i=0;i<n;i++) c[i] = a[i] - p * b[i]; sort(c,c+n); double sum = 0; for(int i=n-1;i>n-1-m;i--) sum += c[i]; if(sum >= 0) return true; else return false; } int main() { //if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit(0);} while(cin>>n>>k && n){ m = n - k; L = 0.0; R = 1.0; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n;i++) cin>>b[i]; while(R - L > 1e-5){ mid = (L + R)/2; //printf("%.2lf\n",mid); if(big(mid)){ L = mid; } else R = mid; //printf("mid%d R%.2lf\n",mid,R); } int ans = floor(100 * L+0.5); printf("%d\n",ans); } return 0; }
相关文章推荐
- POJ 2976 Dropping tests 01分数规划
- POJ 2976 Dropping tests 01分数规划 模板
- POJ 2976 Dropping tests 01分数规划
- [poj 2976]Dropping tests 01分数规划
- POJ 2976 Dropping tests 01分数规划
- POJ-2976 Dropping tests(01分数规划入门)
- POJ 2976 Dropping tests (01分数规划)
- POJ 2976 Dropping tests 01分数规划
- POJ 2976 Dropping tests(普通01分数规划)
- poj 2976: Dropping tests(01分数规划--Dinkelbach算法)
- Poj 2976 Dropping tests【01分数规划+贪心】
- POJ 2976 裸的01分数规划
- 【POJ 2976】Dropping tests&01分数规划详解
- POJ 2976/ZOJ 3068 Dropping tests 01分数规划
- POJ 2976 裸的01分数规划
- POJ 2976 01分数规划基础题目
- POJ-2976:Dropping tests【01分数规划】
- poj-2976 Dropping tests(01分数规划)
- poj-2976-Dropping tests-01分数规划
- POJ 2976 Dropping tests 01分数规划 二分解法