UVA10498 Happiness 【单纯形】
题目链接
题解
模板题
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define cls(s,v) memset(s,v,sizeof(s))
#define mp(a,b) make_pair<int,int>(a,b)
#define cp pair<int,int>
using namespace std;
const int maxn = 25,maxm = 100005;
const double eps = 1e-12,INF = 1e15;
int n,m;
double a[maxn][maxn];
void Pivot(int l,int e){
double t = a[l][e]; a[l][e] = 1;
for (int j = 0; j <= n; j++) a[l][j] /= t;
for (int i = 0; i <= m; i++) if (l != i && fabs(a[i][e]) > 0){
t = a[i][e]; a[i][e] = 0;
for (int j = 0; j <= n; j++) a[i][j] -= a[l][j] * t;
}
}
void simplex(){
while (true){
int l = 0,e = 0; double mn = INF;
for (int j = 1; j <= n; j++) if (a[0][j] > eps){e = j; break;}
if (!e) break;
for (int i = 1; i <= m; i++) if (a[i][e] > eps && a[i][0] / a[i][e] < mn)
mn = a[i][0] / a[i][e],l = i;
Pivot(l,e);
}
}
int main(){
while (~scanf("%d%d",&n,&m)){
REP(j,n) scanf("%lf",&a[0][j]);
REP(i,m){
REP(j,n) scanf("%lf",&a[i][j]);
scanf("%lf",&a[i][0]);
}
a[0][0] = 0;
simplex();
printf("Nasa can spend %lld taka.\n",(LL)floor((-a[0][0]) * m + 1 - eps));
}
return 0;
}
UVA10498 Happiness 【单纯形】的更多相关文章
- UVA 10498 Happiness(线性规划-单纯形)
Description Prof. Kaykobad has given Nasa the duty of buying some food for the ACM contestents. Nasa ...
- BZOJ 2127: happiness [最小割]
2127: happiness Time Limit: 51 Sec Memory Limit: 259 MBSubmit: 1815 Solved: 878[Submit][Status][Di ...
- 单纯形方法(Simplex Method)
最近在上最优理论这门课,刚开始是线性规划部分,主要的方法就是单纯形方法,学完之后做了一下大M算法和分段法的仿真,拿出来与大家分享一下.单纯形方法是求解线性规划问题的一种基本方法. 线性规划就是在一系列 ...
- bzoj 3118: Orz the MST(单纯形)
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3118 题意:给出一个图以及图中指定的n-1条边组成的生成树.每条边权值加1或者减去 ...
- CodeForces114E——Double Happiness(素数二次筛选)
Double Happiness On the math lesson a teacher asked each pupil to come up with his own lucky numbers ...
- [置顶] [BZOJ]2127: happiness 最小割
happiness: Description 高一一班的座位表是个n*m的矩阵,经过一个学期的相处,每个同学和前后左右相邻的同学互相成为了好朋友.这学期要分文理科了,每个同学对于选择文科与理科有着自己 ...
- 数学(线性规划):UVAoj 10498 Happiness
Problem GHappiness! Input: standard inputOutput: standard outputTime Limit: 3 seconds Prof. Kaykobad ...
- BZOJ 3112 Zjoi2013 防守战线 单纯形
题目大意: 单纯形*2.. . #include <cmath> #include <cstdio> #include <cstring> #include < ...
- [补档]happiness
happiness 题目 传送门:http://cogs.pro/cogs/problem/problem.php?pid=1873 高一一班的座位表是个n×m的矩阵,经过一个学期的相处,每个同学和前 ...
随机推荐
- Python模块搜索路径
当一个名为 spam 的模块被导入的时候,解释器首先寻找具有该名称的内置模块.如果没有找到,然后解释器从 sys.path 变量给出的目录列表里寻找名为 spam.py 的文件.sys.path 初始 ...
- Linux命令对应的英文及整体学习法
linux命令 注意一下内容收集与互联网,如果觉得有版权问题,请联系. 用Linux命令的时候,如果熟悉对应英文的含义,更有助于理解相应的命令.man: Manual 意思是手册,可以用这个命令查询其 ...
- First Day!
刚申请博客第一天,多多关照! 小弟,给各位大佬递茶! 出现什么错误, 还请明确指出! 现在, 正在找工作, 如果有老哥, 公司缺人, 何不让老弟我去试试! 不入前端, 不知水深. 一入前端, 如入泥潭 ...
- mac 下删除行末^M 字符
在vi 打开文件模式下进行字符替换 :%s/^M/\r/g //这里的^M是同时按ctrl+v+m获得的,否则会显示找不到^M
- PLSQL面向对象
```sql --定义可被SQL语句调用的子程序 create or replace function getempdept( p_empno emp.empno%type )return ...
- 马赛克是否无法逆转?Python简单消除,看片无忧!
图片水印,轻松去除 前段时间玩过了全民K歌,不知道大家是否玩过,还是做得挺好的,就我这嗓子都能唱出张学友的味道,其中更是有消除噪声的功能,就是朋友们都在吃鸡大叫,我在旁边唱歌依然不受影响. 既然声音可 ...
- 插件使用-HighChart
一.介绍 让数据可视化更简单,兼容 IE6+.完美支持移动端.图表类型丰富.方便快捷的 HTML5 交互性图表库. 官网(英):https://www.highcharts.com/download ...
- centos下配置gitosis服务器
背景: 一台windows电脑,Xshell可以登录centos服务器(centos7.2 64位,有root用户权限),windows电脑已经安装好git和tortoies 在windows下下载和 ...
- oracle 分页的sql语句
已知有两种方法效率上貌似第一种更优: 1. select * from( select t1.*, rownum n from (select * from cm_log order by oper_ ...
- C++ MOOC
相关课程列表: C++远征之起航篇 C++远征之离港篇 C++远征之封装篇 上 C++远征之封装篇 下 C++远征之继承篇 C++远征之多态篇 授课老师:james_yuan 在寒假,我主要选择 C+ ...