题目链接

UVA10498

题解

模板题

#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 【单纯形】的更多相关文章

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

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

  2. BZOJ 2127: happiness [最小割]

    2127: happiness Time Limit: 51 Sec  Memory Limit: 259 MBSubmit: 1815  Solved: 878[Submit][Status][Di ...

  3. 单纯形方法(Simplex Method)

    最近在上最优理论这门课,刚开始是线性规划部分,主要的方法就是单纯形方法,学完之后做了一下大M算法和分段法的仿真,拿出来与大家分享一下.单纯形方法是求解线性规划问题的一种基本方法. 线性规划就是在一系列 ...

  4. bzoj 3118: Orz the MST(单纯形)

    题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3118 题意:给出一个图以及图中指定的n-1条边组成的生成树.每条边权值加1或者减去 ...

  5. CodeForces114E——Double Happiness(素数二次筛选)

    Double Happiness On the math lesson a teacher asked each pupil to come up with his own lucky numbers ...

  6. [置顶] [BZOJ]2127: happiness 最小割

    happiness: Description 高一一班的座位表是个n*m的矩阵,经过一个学期的相处,每个同学和前后左右相邻的同学互相成为了好朋友.这学期要分文理科了,每个同学对于选择文科与理科有着自己 ...

  7. 数学(线性规划):UVAoj 10498 Happiness

    Problem GHappiness! Input: standard inputOutput: standard outputTime Limit: 3 seconds Prof. Kaykobad ...

  8. BZOJ 3112 Zjoi2013 防守战线 单纯形

    题目大意: 单纯形*2.. . #include <cmath> #include <cstdio> #include <cstring> #include < ...

  9. [补档]happiness

    happiness 题目 传送门:http://cogs.pro/cogs/problem/problem.php?pid=1873 高一一班的座位表是个n×m的矩阵,经过一个学期的相处,每个同学和前 ...

随机推荐

  1. hadoop组件概念理解

    一.HADOOP 二.HIVE 三.SQOOP 1.来由和作用 sqoop由一些封装好的MR程序的jar包构成,后演变成框架,但sqoop只有map任务没有reduce任务. 用于 hdfs.hive ...

  2. 绝对干货!初学者也能看懂的DPDK解析

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由Willko发表于云+社区专栏 一.网络IO的处境和趋势 从我们用户的使用就可以感受到网速一直在提升,而网络技术的发展也从1GE/10 ...

  3. 局域网arpspoof欺骗获取cookie/图片/密码

    开启路由转发功能 查看IP转发功能是否打开 默认是不开起,0,我这里是修改后的,显示1. 修改转发功能,1为允许. 修改成功后再进行Arpspoof欺骗 如果开始劫持后,自己电脑无法联网了 ??? 检 ...

  4. 使用FFMPEG 压缩png图片 与tinypng压缩结果对比

    Tinypng  https://tinypng.com/ 一个在线png压缩工具 FFmpeg https://ffmpeg.org/download.html 原图 903 kb Tinypng压 ...

  5. Vue.js 相关知识(基础)

    1. Vue.js 介绍 Vue,读音 /vjuː/,类似于 view),是一套用于构建用户界面的渐进式框架(重点在于视图层). 作者:尤雨溪 注:学习 vue.js 时,一定要抛弃 jQuery 的 ...

  6. php 常用英语小汇

    bstract抽象的 -挨伯丝拽克特 access存取.访问 -挨克色丝 account账户 -厄靠恩特 action动作 -爱克身 activate激活 -爱克特维特 active活动的 -爱克得 ...

  7. web.xml配置文件中<async-supported>true</async-supported>报错

    web.xml配置文件中<async-supported>true</async-supported>报错 http://blog.csdn.net/dream_ll/arti ...

  8. DataGridView 复选框 操作大全

    DataGridViewCheckBoxColumn dtCheck = new DataGridViewCheckBoxColumn(); dtCheck.DataPropertyName = &q ...

  9. Software Defined Networking(Week 1)

    前言 课程名称:软件定义网络 课程地址 Coursera上新的一期还没开课,所以是YouTube. Instructor:Nick Feamster Get Started 对于本次课程,主要的新内容 ...

  10. iOS- Exception Type: 00000020:什么是看门狗机制

      1.前言    前几天我们项目闪退之后遇到的一个Crash,之后逛了许多论坛,博客都没有找到满意的回复  在自己做了深入的研究之后,对iOS的看门狗机制有了一个基本的了解  而有很多奇怪的Cras ...