Problem G
Happiness!

Input: standard
input
Output: standard output
Time Limit: 3
seconds

Prof. Kaykobad has given Nasa the duty of buying
some food for the ACM contestents. Nasa decided to buy n different items.
He then asked each of the m contestents how much of each item they want
to eat. They could not give any logical answer, they only want as much as they
wish! Nasa knows quite well that they would only waste their food if they get as
much as they want. He was determined not to let that happen.

So he tactfully found out from each of the
contestents how much 'happiness' one gets from each piece of each item and what
is the 'total happiness' over which one wastes food. It may be the case that
someone gets 'zero' 'happiness' on some item(s). He decided that he would never
let anyone have such amount of food that exceeds his 'total happiness'. He
planned that he would give someone even a fraction of a piece of item, but never
give anyone more than he needed!

He also decided that each would get exactly the
same amount of each item so that no one can complain against him.

After planning all these, he finally realized that
he has an infinite amount of money and hence, he would spend as much money as he
can.

Input

Input contains data collected by Nasa on
several days.

For each day,

The first line contains the
integers n(3<=n<=20) and m(3<=m<=20).

The next line contains n
real numbers, the per unit price of each item.

Each of the next m lines
contain data (n+1 real numbers) of each contestents: first n are 'happiness' got
from each item and the last one is the 'total happiness'.

Output

For the data
collected in each day print in a single line the maximum amount of money Nasa
can spend in taka rounded up to nearest integer. You can assume that there will be no such input which may cause
serious floating point errors.

Sample Input

3 3
1 0.67 1.67
1 2 1 430
3 0 2 460
1 4 0 420

Sample Output

Nasa can spend 1354 taka.
  
  这是线性规划模版题。
 #include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
const double EPS = 1e-;
const int MAXN = ;
const int INF = 0x3fff3fff; inline int sgn(double x) {
return (x>EPS)-(x<-EPS);
} double A[MAXN][MAXN];
double b[MAXN],c[MAXN];
int N[MAXN],B[MAXN];
int n,m;
double v; bool init() {
N[]=B[]=v=;
for(int i=;i<=n;++i)N[++N[]]=i;
for(int i=;i<=m;++i)B[++B[]]=n+i;
return true;
} void pivot(int l,int e){
b[e]=b[l]/A[l][e];
A[e][l]=1.0/A[l][e];
for(int i=;i<=N[];++i){
int &x=N[i];
if(x!=e)A[e][x]=A[l][x]/A[l][e];
}
for(int i=;i<=B[];++i)if(B[i]!=){
int y=B[i];
b[y]-=A[y][e]*b[e];
A[y][l]=-A[y][e]*A[e][l];
for(int j=;j<=N[];++j){
int x=N[j];
if(x!=e)A[y][x]-=A[e][x]*A[y][e];
}
}
v+=b[e]*c[e];
c[l]=-A[e][l]*c[e];
for(int i=;i<=N[];++i) {
int x=N[i];
if(x!=e)c[x]-=A[e][x]*c[e];
}
for(int i=;i<=N[];++i)if(N[i]==e)N[i]=l;
for(int i=;i<=B[];++i)if(B[i]==l)B[i]=e;
} bool simplex() {
while(true) {
int e=MAXN;
for(int i=;i<=N[];++i) {
int x=N[i];
if(sgn(c[x])>&&x<e)e=x;
}
if(e==MAXN) break;
double delta=-;
int l=MAXN;
for(int i=;i<=B[];++i) {
int y=B[i];
if(sgn(A[y][e])>){
double tmp=b[y]/A[y][e];
if(delta==-||sgn(tmp-delta)<||(sgn(tmp-delta)==&&y<l)){
delta=tmp;
l=y;
}
}
}
if(l==MAXN) return false;
pivot(l,e);
}
return true;
} int main() {
while(scanf("%d%d",&n,&m)!=EOF) {
for(int i=;i<=n;++i)
scanf("%lf",&c[i]);
for(int i=;i<=m;++i){
for(int j=;j<=n;++j)
scanf("%lf",&A[n+i][j]);
scanf("%lf",&b[n+i]);
}
init();
simplex();
printf("Nasa can spend %d taka.\n",(int)ceil(v*m));
}
}

数学(线性规划):UVAoj 10498 Happiness的更多相关文章

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

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

  2. UVa 10498 Happiness! (线性规划)

    题意 将N种食品分给m个参赛选手,一个单位的某食品给某个选手一定满足度,每个选手有一个最大满足度.为了避免浪费,分给每一个选手的食品都不超越选手的满足度.已知的各种食品的单价,求最多可以花的钱. 思路 ...

  3. 数学:UVAoj 11174 Stand in a Line

    Problem J Stand in a Line Input: Standard Input Output: Standard Output All the people in the bytela ...

  4. Android不规则点击区域详解

    Android不规则点击区域详解 摘要 今天要和大家分享的是Android不规则点击区域,准确说是在视觉上不规则的图像点击响应区域分发. 其实这个问题比较简单,对于很多人来说根本不值得做为一篇博文写出 ...

  5. 【数学建模】线性规划各种问题的Python调包方法

    关键词:Python.调包.线性规划.指派问题.运输问题.pulp.混合整数线性规划(MILP) 注:此文章是线性规划的调包实现,具体步骤原理请搜索具体解法.   本文章的各个问题可能会采用多种调用方 ...

  6. Python小白的数学建模课-03.线性规划

    线性规划是很多数模培训讲的第一个算法,算法很简单,思想很深刻. 要通过线性规划问题,理解如何学习数学建模.如何选择编程算法. 『Python小白的数学建模课 @ Youcans』带你从数模小白成为国赛 ...

  7. 使用Python scipy linprog 线性规划求最大值或最小值(使用Python学习数学建模笔记)

    函数格式 scipy.optimize.linprog(c, A_ub=None, b_ub=None, A_eq=None, b_eq=None, bounds=None, method='simp ...

  8. 数学(线性规划): ZJOI2013 防守战线

    偷懒用的线性规划. #include <iostream> #include <cstring> #include <cstdio> using namespace ...

  9. Python数学建模系列(一):规划问题之线性规划

    @ 目录 前言 线性规划 样例1:求解下列线性规划问题 scipy库求解 样例2:求解下列线性规划问题 pulp库求解 样例3.运输问题 说明 结语 前言 Hello!小伙伴! 非常感谢您阅读海轰的文 ...

随机推荐

  1. 一致性哈希(Consistent Hash)

    http://blog.csdn.net/cywosp/article/details/23397179/ http://www.codeproject.com/Articles/56138/Cons ...

  2. [HNOI2012] 矿场搭建

    /* codevs 1996 连通性问题 Tarjan+割点 可以感性的想一想 一定炸割点最好 否则 没有什么影响 先求出割点来 对于剩下的点们 缩一下 当然不能包括割点 这里的缩 因为删了割点就不是 ...

  3. WPF 媒体播放器(MediaElement)实例,实现进度和音量控制

    WPF 视频音频播放控件MediaElement实现进度控制,音量控制实例 说明: 1.Volume控制音量的大小,double类型,并且实现了属性依赖,可以用来双向绑定:在 0 和 1. 之间的线性 ...

  4. window.showModalDialog()复制内容

    ShowModalDialog 打开的 页面上加入个 <span id="mySpan" name="mySpan" contentEditable=&q ...

  5. PHP 进行统一邮箱登陆的代理实现(swoole)

    在工作的过程中,经常会有很多应用有发邮件的需求,这个时候需要在每个应用中配置smtp服务器.一旦公司调整了smtp服务器的配置,比如修改了密码等,这个时候对于维护的人员来说要逐一修改应用中smtp的配 ...

  6. 浅谈html5某些新元素的用途

    大家都知道html是一种前端网页语言,从出现到现在已经经历了很多的版本了,但是随着html的不断发展,现在的html5已经不再是单一的前端页面语言了,html,javascript,css不再单纯的只 ...

  7. AngularJS+NodeJS环境搭建

    需要安装的软件: node-v0.12.7-x64.msi python-2.7.10.amd64.msi Git-2.5.1-64-bit.exe (注意:Git安装时,需要选择的步骤)  安装位置 ...

  8. c++实现的Array数据结构

    1.Array.h,Array<T>的定义 template <class T> class Array { protected: T *data; //一个指向数组数据的指针 ...

  9. 【POJ2886】【线段树】Who Gets the Most Candies?

    Description N children are sitting in a circle to play a game. The children are numbered from 1 to N ...

  10. H5相关

    对于容器元素,尤其在做移动端产品时候,我们很自然会让其居中定位: .container { position: absolute; left: %; top: %; transform: transl ...