单纯形&&线性规划
沦为了背板子...wyfcyx的ppt
#include<bits/stdc++.h>
using namespace std;
const int N = ;
const double eps = 1e-, inf = 1e18;
int n, m, l, e, t;
double k;
double a[N][N], ans[N];
int id[N << ];
void pivot(int l, int e)
{
swap(id[n + l], id[e]);
double r = a[l][e]; a[l][e] = ;
for(int i = ; i <= n; ++i) a[l][i] /= r;
for(int i = ; i <= m; ++i) if(i != l)
{
double r = a[i][e]; a[i][e] = ;
for(int j = ; j <= n; ++j) a[i][j] -= r * a[l][j];
}
}
int main()
{
scanf("%d%d%d", &n, &m, &t);
for(int i = ; i <= n; ++i) scanf("%lf", &a[][i]), id[i] = i;
for(int i = ; i <= m; ++i)
{
for(int j = ; j <= n; ++j) scanf("%lf", &a[i][j]);
scanf("%lf", &a[i][]);
}
while(true)
{
l = e = ; k = -eps;
for(int i = ; i <= m; ++i) if(a[i][] < k) { l = i; k = a[i][]; }
if(!l) break;
for(int i = n; i; --i) if(a[l][i] < -eps)
{ e = i; break; }
if(!e) { puts("Infeasible"); return ; }
pivot(l, e);
}
while(true)
{
l = e = ;
for(int i = ; i <= n; ++i) if(a[][i] > eps)
{ e = i; break; }
if(!e) break;
k = inf;
for(int i = ; i <= m; ++i) if(a[i][e] > eps && a[i][] / a[i][e] < k)
{ k = a[i][] / a[i][e]; l = i; }
if(!l) { puts("Unbounded"); return ; }
pivot(l, e);
}
printf("%.10f\n", -a[][]);
if(!t) return ;
for(int i = ; i <= m; ++i) ans[id[i + n]] = a[i][];
for(int i = ; i <= n; ++i) printf("%.10f ", ans[i]);
return ;
}
单纯形&&线性规划的更多相关文章
- 软件推荐-国内参数优化软件:1stOpt - First Optimizationg
首页:http://www.7d-soft.com/index.htm 4.0新功能 (预定2010年8月6日): 1:支持复数拟合.复数方程组计算: 2:支持微分方程拟合求解: 3:通用全局优化求解 ...
- BZOJ.1061.[NOI2008]志愿者招募(线性规划 对偶原理 单纯形 / 费用流SPFA)
题目链接 线性规划 用\(A_{ij}=0/1\)表示第\(i\)天\(j\)类志愿者能否被招募,\(x_i\)为\(i\)类志愿者招募了多少人,\(need_i\)表示第\(i\)天需要多少人,\( ...
- 【UOJ #179】线性规划 单纯形模板
http://uoj.ac/problem/179 终于写出来了单纯性算法的板子,抄的网上大爷的qwq 辅助线性规划找非基变量时要加个随机化才能A,我也不知道为什么,卡精度吗? 2017-3-6UPD ...
- LP线性规划求解 之 单纯形 算法
LP线性规划求解 之 单纯形 算法 认识-单纯形 核心: 顶点旋转 随机找到一个初始的基本可行解 不断沿着可行域旋转(pivot) 重复2,直到结果不能改进为止 案例-过程 以上篇的case2的松弛型 ...
- 线性规划(Simplex单纯形)与对偶问题
线性规划 首先一般所有的线性规划问题我们都可以转换成如下标准型: 但是我们可以发现上面都是不等式,而我们计算中更希望是等式,所以我们引入这个新的概念:松弛型: 很显然我们最后要求是所有的约束左边的变量 ...
- 线性规划之单纯形算法矩阵描述与python实现
声明 本文为本人原创,转载请注明出处.本文仅发表在博客园,作者LightningStar. 问题描述 所有的线性规划问题都可以归约到标准型的问题,规约过程比较简单且已经超出本文范围,不再描述,可以参考 ...
- UVA 10498 Happiness(线性规划-单纯形)
Description Prof. Kaykobad has given Nasa the duty of buying some food for the ACM contestents. Nasa ...
- 单纯形求解线性规划(BZOJ1061)
推荐一篇论文:http://wenku.baidu.com/view/ce5784754a7302768f99391d 我们设xi为第i个志愿者的招募次数,以样例为例,则不难列出如下的线性规划方程: ...
- 【UOJ#179】线性规划 单纯形
题目链接: http://uoj.ac/problem/179 Solution 就是单纯形模板题,这篇博客就是存一下板子. Code #include<iostream> #includ ...
随机推荐
- css 实现鼠标滑过流光效果
来划我啊 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...
- Codeforces 280C - Game on Tree
传送门:280C - Game on Tree 不知道期望是啥的请自行Baidu或Google,(溜了 题目大意,有一棵有根树,每次随机选择一个节点,将这个节点和它的子树删除,问将整棵树删除的期望次数 ...
- linux diff3-比较3个文件不同的地方
推荐:更多Linux 文件查找和比较 命令关注:linux命令大全 diff3命令用于比较3个文件,将3个文件的不同的地方显示到标准输出. 语法 diff3(选项)(参数) 选项 -a:把所有的文件都 ...
- 洛谷 1339 [USACO09OCT]热浪Heat Wave
[题解] 最短路.那么直接写dijkstra就好了. #include<cstdio> #include<algorithm> #include<cstring> ...
- 百练4152:最佳加法表达式(dp+高精度)
描述 给定n个1到9的数字,要求在数字之间摆放m个加号(加号两边必须有数字),使得所得到的加法表达式的值最小,并输出该值.例如,在1234中摆放1个加号,最好的摆法就是12+34,和为36 输入有不超 ...
- Mysql学习总结(42)——MySql常用脚本大全
备份 (所有) C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqldump --no-defaults -hlocalhost -P3306 -u ...
- BNUOJ 5966 Rank of Tetris
Rank of Tetris Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ...
- empty array & Array.from
empty array bug const duplicationArray = (arr = [], times = 2, debug = false) => { let result = [ ...
- SpringBoot 拦截器--只允许进入登录注册页面,没登录不允许查看其它页面
SpringBoot注册登录(一):User表的设计点击打开链接 SpringBoot注册登录(二):注册---验证码kaptcha的实现点击打开链接 SpringBoot注册登录(三):注册--验证 ...
- 在Myeclipse中拷贝一个web项目,但是tomcat文件夹中没有更新,需要进行修改才能更新。
1.在Myeclipse中拷贝一个web项目,但是tocat文件夹中没有更新,需要进行修改才能更新. 2.方法:右键这个工程,然后Properties->MyEclipse->Projec ...