POJ 2976 Dropping tests(01分数规划)
2015-05-11 11:21
375 查看
01分数规划
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1005;
typedef long long ll;
int n, k;
double a
, b
, tmp
;
bool cmp(double a, double b) {
return a > b;
}
int main() {
while (~scanf("%d%d", &n, &k) && n || k) {
for (int i = 0; i < n; i++) scanf("%lf", &a[i]);
for (int i = 0; i < n; i++) scanf("%lf", &b[i]);
double l = 0, r = 1e15;
for (int i = 0; i < 200; i++) {
double mid = (l + r) / 2;
for (int j = 0; j < n; j++) tmp[j] = a[j] - b[j] * mid;
sort(tmp, tmp + n, cmp);
double sum = 0;
for (int j = 0; j < n - k; j++) sum += tmp[j];
if (sum < 0) r = mid;
else l = mid;
}
printf("%lld\n", (ll)(l * 100 + 0.5));
}
return 0;
}
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1005;
typedef long long ll;
int n, k;
double a
, b
, tmp
;
bool cmp(double a, double b) {
return a > b;
}
int main() {
while (~scanf("%d%d", &n, &k) && n || k) {
for (int i = 0; i < n; i++) scanf("%lf", &a[i]);
for (int i = 0; i < n; i++) scanf("%lf", &b[i]);
double l = 0, r = 1e15;
for (int i = 0; i < 200; i++) {
double mid = (l + r) / 2;
for (int j = 0; j < n; j++) tmp[j] = a[j] - b[j] * mid;
sort(tmp, tmp + n, cmp);
double sum = 0;
for (int j = 0; j < n - k; j++) sum += tmp[j];
if (sum < 0) r = mid;
else l = mid;
}
printf("%lld\n", (ll)(l * 100 + 0.5));
}
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分数规划
- 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 Dropping tests(01分数规划 牛顿迭代)
- POJ 2976- Dropping tests -01分数规划