题意:

思路:单纯形模板

 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. SpringBoot 2.x (6):使用Filter、Servlet、Listener

    Filter的使用: 1.常见的默认Filter有: characterEncodingFilter hiddenHttpMethodFilter httpPutFormContentFilter r ...

  2. Java开发笔记(九十四)文件通道的性能优势

    前面介绍了字节缓存的一堆概念,可能有的朋友还来不及消化,虽然文件通道的用法比起传统I/O有所简化,可是平白多了个操控繁琐的字节缓存,分明比较传统I/O更加复杂了.尽管字节缓存享有缓存方面的性能优势,但 ...

  3. 十个 JDBC 的最佳实践

    JDBC是Java为多种关系型数据库提供的统一的访问接口,以下是我长期使用JDBC总结的十个最佳实践. 1. 使用PrearedStatement 任何一个使用过JDBC的Java程序员几乎都知道这个 ...

  4. Web服务器安全设置

    Web服务器安全方面一直重视程度不够,是各种网站经常被黑的主要原因.下面笔者总结了一下关于怎样保证Web服务器安全的措施,希望能给那些服务器尚存在漏洞的用户提供一些帮助. 本文主要以Windows s ...

  5. COGS 827. [Tyvj Feb11] 网站计划

    输入文件:web.in   输出文件:web.out   简单对比时间限制:1 s   内存限制:128 MB 描述 Description     Tyvj的Admin--zhq同学将在寒假开始实行 ...

  6. 【转载】SQL Server 2012 日志传送

    SQL Server 2012 日志传送 一.准备: 数据库为完全恢复模式,并事先做一次完全备份. 共享一个文件夹,主机备份放在这个文件夹,而且客户机有权访问这个共享文件夹. 二.基本配置 1.启动配 ...

  7. Linux php安装zip扩展

    Linux php安装zip扩展 2018.07.22 22:40 1165浏览   #wget http://pecl.php.net/get/zip-1.12.4.tgz #tar zxfv zi ...

  8. hard fault 学习记录

    使用 segger 的 hard fault 的源文件后,当调试时,发生硬件错误的时候,可以查看 HardFaultRegs 中的内容,并对比 segger_HardFaultHandler.c 中的 ...

  9. CAD交互绘制矩形框(网页版)

    主要用到函数说明: _DMxDrawX::DrawLine 绘制一个直线.详细说明如下: 参数 说明 DOUBLE dX1 直线的开始点x坐标 DOUBLE dY1 直线的开始点y坐标 DOUBLE ...

  10. css实现水平/垂直居中效果

    一.如果是已知宽高的元素做水平/垂直居中效果的话,可以直接用具体的数值指定定位布局或偏移布局,这个就不过多讨论.这里主要介绍在不知宽高或需要弹性布局下的几种实现方式. 二.1.table表格法思路:显 ...