题目链接

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. DICOM 协议学习笔记之 What is DICOM

    什么是DICOM? Dicom (Digital Imaging and Communications in Medicine)即医学数字成像和通信,是医学图像和相关信息的国际标准(ISO 12052 ...

  2. Docker Zero Deployment and Secrets (二)

    一. 健康检测: (1)定义检测信息如下(案例,在Dockerfile中定义) FROM alpine:3.6 ... HEALTHCHECK --interval=30s \     --timeo ...

  3. hadoop之定制自己的sort过程

    Key排序 1. 继承WritableComparator 在hadoop之Shuffle和Sort中,可以看到mapper的输出文件spill文件需要在内存中排序,并且在输入reducer之前,不同 ...

  4. runlevel 命令详解

    基础命令学习目录首页 原文链接:https://blog.csdn.net/PecoVio/article/details/82428883 runlevel 知识扩展 linux操作系统自从开始启动 ...

  5. (转)Django 数据库

         转:https://blog.csdn.net/ayhan_huang/article/details/77575186      目录 数据库说明 配置数据库 在屏幕输出orm操作对应的s ...

  6. 软件功能说明书final修订

    贪吃蛇(单词版)软件功能说明书final修订 1 开发背景 “贪吃蛇”这个游戏对于80,90后的人来说是童年的记忆,可以将其说为是一个时代的经典,实现了传统贪吃蛇的游戏功能:现在人们对英语的重视程度越 ...

  7. (第六周)课上Scrum站立会议演示

    组名:连连看 组长:张政 组员:张金生.李权.武志远 时间:2016.10.13   20:20——20:40 会议内容: 已完成的内容: 1.选定编译语言,安装软件并配置环境,完成了游戏的基本模型. ...

  8. 奔跑吧DKY——团队Scrum冲刺阶段-Day 1-领航

    各个成员在 Alpha 阶段认领的任务 修改 序号 修改 具体描述 1 游戏过程 取消原来的跳跃和俯身按钮,保留跳跃的功能,可以触屏滑动来躲避地面障碍物,也可以躲避另一种陷阱障碍物 2 闯关功能 取消 ...

  9. 图论 Kruskal算法 并查集

    #include<iostream> #include<cstring> #include<string> #include<cstdio> #incl ...

  10. JAVA自学日记——Part Ⅰ.

    和C++比较相似,Java同样是面向对象的设计语言,在基础的语句上有一些不大的差别,经过两天的学习,大概的了解了在eclipse中如何进行简单的编程,解决一些简单的问题,诸如在学习C时做过的“字符串倒 ...