题意:

思路:单纯形模板

 var a:array[..,..]of double;
idx,idy,q:array[..]of longint;
c:array[..]of double;
n,m,i,j,op,x,y:longint;
eps,mn:double; procedure swap(var x,y:longint);
var t:longint;
begin
t:=x; x:=y; y:=t;
end; procedure pivot(x,y:longint);
var i,j,tot:longint;
tmp:double;
begin
swap(idy[x],idx[y]);
tmp:=a[x,y]; a[x,y]:=/a[x,y];
for i:= to n do
if y<>i then a[x,i]:=a[x,i]/tmp;
tot:=;
for i:= to n do
if (i<>y)and((a[x,i]>eps)or(a[x,i]<-eps)) then
begin
inc(tot); q[tot]:=i;
end;
for i:= to m do
begin
if (x=i)or((a[i,y]<eps)and(a[i,y]>-eps)) then continue;
for j:= to tot do a[i,q[j]]:=a[i,q[j]]-a[x,q[j]]*a[i,y];
a[i,y]:=-a[i,y]/tmp;
end;
end; begin
//assign(input,'uoj179.in'); reset(input);
//assign(output,'uoj179.out'); rewrite(output);
readln(n,m,op);
randomize;
eps:=1e-8;
for i:= to n do read(a[,i]);
for i:= to m do
begin
for j:= to n do read(a[i,j]);
read(a[i,]);
end;
for i:= to n do idx[i]:=i;
for i:= to m do idy[i]:=i+n;
while true do
begin
x:=; y:=;
for i:= to m do
if (a[i,]<-eps)and((x=)or(random()=)) then x:=i;
if x= then break;
for i:= to n do
if (a[x,i]<-eps)and((y=)or(random()=)) then y:=i;
if y= then
begin
writeln('Infeasible');
// close(input);
//close(output);
exit;
end;
pivot(x,y);
end;
while true do
begin
x:=; y:=; mn:=1e15;
for i:= to n do
if a[,i]>eps then begin y:=i; break; end;
if y= then break;
for i:= to m do
if (a[i,y]>eps)and(a[i,]/a[i,y]<mn) then
begin
mn:=a[i,]/a[i,y]; x:=i;
end;
if x= then
begin
writeln('Unbounded');
// close(input);
// close(output);
exit;
end;
pivot(x,y);
end;
writeln(-a[,]::);
if op= then exit;
for i:= to m do
if idy[i]<=n then c[idy[i]]:=a[i,];
for i:= to n do
begin
write(c[i]::);
if i<n then write(' ');
end; //close(input);
//close(output);
end.

【UOJ179】线性规划(单纯形)的更多相关文章

  1. 【UOJ #179】线性规划 单纯形模板

    http://uoj.ac/problem/179 终于写出来了单纯性算法的板子,抄的网上大爷的qwq 辅助线性规划找非基变量时要加个随机化才能A,我也不知道为什么,卡精度吗? 2017-3-6UPD ...

  2. UVA 10498 Happiness(线性规划-单纯形)

    Description Prof. Kaykobad has given Nasa the duty of buying some food for the ACM contestents. Nasa ...

  3. UOJ179 线性规划

    Description 这是一道模板题. 本题中你需要求解一个标准型线性规划: 有\(n\)个实数变量\(x_1,x_2,\cdots,x_n\)和\(m\)条约束,其中第\(i\)条约束形如\(\s ...

  4. 【UOJ#179】线性规划 单纯形

    题目链接: http://uoj.ac/problem/179 Solution 就是单纯形模板题,这篇博客就是存一下板子. Code #include<iostream> #includ ...

  5. UOJ.179.线性规划(单纯形)

    题目链接 这写得还不错:http://www.cnblogs.com/zzqsblog/p/5457091.html 引入基变量\(x_{i+n}\),将约束\(\sum_{i=1}^m a_{ij} ...

  6. 线性规划VB求解

    线性规划VB求解 Rem 定义动态数组 Dim a() As Single, c() As Single, b() As Single, cb() As Single Dim aa() As Sing ...

  7. 机器学习-线性规划(LP)

    线性规划问题 首先引入如下的问题: 假设食物的各种营养成分.价格如下表: Food Energy(能量) Protein(蛋白质) Calcium(钙) Price Oatmeal(燕麦) 110 4 ...

  8. BZOJ 1061: [Noi2008]志愿者招募

    1061: [Noi2008]志愿者招募 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 4064  Solved: 2476[Submit][Stat ...

  9. 【置顶】Trotyl's OI tree

    \(\rm thx\):@\(\rm UntilMadow\) ! \(\color{Green}{\rm Pupil}\) :只会一点点 \(\color{blue}{\text{Expert}}\ ...

  10. PKUSC 2022 口胡题解

    \(PKUSC\ 2022\)口胡题解 为了更好的在考试中拿分,我准备学习基础日麻知识(为什么每年都考麻将 啊啊啊) 首先\(STO\)吉老师\(ORZ,\)真的学到了好多 观察标签发现,这套题覆盖知 ...

随机推荐

  1. NIO服务端主要创建过程

    NIO服务端主要创建过程:   步骤一:打开ServerSocketChannel,用于监听客户端的连接,它是所有客户端连接的副管道,示例代码如下:      ServerSocketChannel ...

  2. H+后台主题UI框架---整理(三)

    这里面介绍下H+后台主题UI框架里面插件的应用,不过都是最最简单最初级的功能.主要有日历插件,input单选多选(icheck)插件,input下拉搜索(chosen)插件. 一.日历插件 有如下几种 ...

  3. re正则表达式讲解—初步认识

    # f = open(r"C:\Users\LENOVO\Desktop\模特.txt",'r') # 1.常规提取文档内容方法 # contacts = [] # for i i ...

  4. PKU_campus_2018_A Wife

    思路: 题目链接http://poj.openjudge.cn/practice/C18A/ 先说一个结论,每一天要么7要么0,由此提供一种状态压缩dp的解法. 实现: #include <bi ...

  5. ASP.NET Web API FilterAttribute假想

    偶然的测试发现API FilterAttribute没用引用只会初始化一次 比如: 如果是 Global Action Filter, 则全局只会初始化一次 针对于不同的Controller级别的Ac ...

  6. layer设置弹出全屏

    //弹出即全屏 var index = layer.open({ type: , content: 'http://www.layui.com', area: ['300px', '195px'], ...

  7. js函数中获得当前被点击元素

    问题描述:在html页面中点击<a>或者’按钮‘,进入js中的函数,在js函数中获得被点击那个<a>或‘按钮’元素 解决方法:方法一: html中: <a>标签:& ...

  8. 【C++】双边滤波器(bilateral filter)

    Bilateral Filtering for Gray and Color Images 双边滤波器:保留边界的平滑滤波器. 在局部上,就是在灰度值差异不大的区域平滑,在灰度值差异比较大的边界地区保 ...

  9. uva12265 Selling Land

    见紫书.(c,h)的更新策略://前面的高度为0了,直接插入因为ans==-c+h,c大,h还小,那么肯定不是最优左上角,更新新加入列的列//新的一列高度最小,就删掉了其他的,只留这个高度从上到下,从 ...

  10. 转行做web前端,该如何进行短期快速自学,达到高新就业水平

    就目前来说,毕业生如果想毕业就找到高薪的工作,互联网成为了第一个选择,在所有的职业中,不靠任何关系,全凭自己的能力就业,就是程序开发,而web前端开发是目最很热门的行业,在未来五年之内,web前端开发 ...