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的矩阵,经过一个学期的相处,每个同学和前 ...
随机推荐
- 用Unity的UGUI实现简单摇杆
1.在Canvas下新建一个空对象作为我们的摇杆,命名为Joystick. 摇杆由背景和杆两部分组成,所以在Joystick下新建一个Image作为摇杆的背景,命名为BG. 在BG下新建一个Image ...
- grok正则
USERNAME [a-zA-Z0-9._-]+ USER %{USERNAME} INT (?:[+-]?(?:[0-9]+)) BASE10NUM (?<![0-9.+-])(?>[+ ...
- ffplay.exe操作方式
大牛博客: 博文名称:[总结]FFMPEG视音频编解码零基础学习方法 博文链接:http://blog.csdn.net/leixiaohua1020/article/details/15811977 ...
- Flask之笔记集合
目录 一.简述 二.基本使用 三.配置文件 四.路由系统 2.自定义正则路由 五.模版语言 六.请求和响应 七.Session 2.自定义session 八.蓝图 九.message 十.中间件 十一 ...
- jsp九大内置对象之二response
这里主要写response向浏览器输出数据时的编码,输出数据有两种: response.getOutStram().write("讲讲".getBytes("utf-8& ...
- PAT 1001 A+B Fotmat
源码 1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Calcula ...
- 1001. A+B Format (20)的解题思路以及多源代码文件的尝试编写
前言 这几天刚学了多源代码文件的编译,因为想尝试使用一下这种方法,所以想用此编写这次作业的程序.正好可以learning by doing,在做当中学习新知识.(编译器为Dev-C++) github ...
- “吃神么,买神么”的第二个Sprint计划(总结)
“吃神么,买神么”项目Sprint计划 ——5.28 星期四(第八天)第一次Spring计划结束 第一阶段Spring的目标以及完成情况: 时间:5月21号~5月28号(7天) 目标:第二阶段主 ...
- 第一个spring冲刺团队贡献分(80分满分)
团队贡献分(80分满分): 李泳江 24 叶煜稳 26 谢洪跃 18 周伟雄 12
- 【CSAPP笔记】12. 高速缓存存储器
高速缓存存储器 在存储层次结构中,高速缓存存储器,也叫 cache 是最接近 CPU 寄存器的那一块. 更一般而言,缓存(caching)是一个无所不在的技术.缓存的意思是:对于每层的存储设备,位于 ...