POJ 3757
来源:互联网 发布:xbox one s 手柄 淘宝 编辑:程序博客网 时间:2024/04/29 19:45
cost=sigma(fi*ci)
vi=pi*bi/(pi+bi);
sigma(vi)*t=F;
fi=vi*t;
cost=simga(ci*fi)=sigma(ci*vi*t)=sigma(ci*vi)*t=sigma(ci*vi)*F/(sigma(vi)) 分数规划
此题优化后的 二分居然只比迭代 慢20ms 以下是迭代的代码
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;const int maxn = 211111;const double eps = 1e-6;typedef long long LL;struct node {double w, v, val;node() {}node(double w, double v) :w(w), v(v) {val = 0;}bool operator<(const node& t) const {return val < t.val;}} f[maxn];double F;int main() {int n, k, i;double w, p, b, v, c;scanf("%d%d%lf", &n, &k, &F);for (i = 0; i < n; ++i) {scanf("%lf%lf%lf", &p, &b, &c);v = (p * b) / (p + b);f[i] = node(v * c * F, v);}double rate = 0, pre = -100;rate = f[0].w / f[0].v;for (i = 0; i < n; ++i)f[i].val = f[i].w - f[i].v * rate;while (fabs(rate - pre) > eps) {pre = rate;w = v = 0;sort(f, f + n);for (i = 0; i < k; ++i)w += f[i].w, v += f[i].v;rate = w / v;for (i = 0; i < n; ++i)f[i].val = f[i].w - f[i].v * rate;}printf("%.4f\n", rate);return 0;}
- POJ 3757
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- redhat新建用户作为ftp用户
- pthread_cond 类函数
- 实战 SSH 端口转发
- 入门经典 例题9-3 硬币问题
- 设计模式 - 访问者模式
- POJ 3757
- PHP最佳实践
- 4.2 daydream
- windows 多线程编程的几点经验 (防止死锁)
- 让C#程序自动以管理员方式运行
- php与protoBuffer入门例子
- predis操作大全
- TopCoder: RevolvingDoors BFS算法
- 关于adapter change与listView同步的错误。