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. ecshop了解01

    ecshop 是一个基于b2c的开源商城系统,从现在起来我也来学习一下,它是基于面向对象的,当然里面也有类. ecshop 的目录介绍 上面简单介绍一个ecshop的几个主要的文件,上面已经截图给大家 ...

  2. android EventBus 的使用

    今天简单的介绍 一下啊 android  EventBus 的使用 EventBus 在官方介绍中是订阅......什么的 一大堆  ,  在我android 菜鸟眼里 就是用来代替android 广 ...

  3. 自定义图文混排视图MyImageTextView

    http://blog.csdn.net/xujunfeng000/article/details/36399339?utm_source=tuicool&utm_medium=referra ...

  4. if elsif;报错;new赋值

    1. IF INSERTING THEN          BEGIN 中间不能为空          END;ELSIF DELETING THEN         BEGIN          E ...

  5. HDU5311 Hidden String

    Problem Description Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets a str ...

  6. SVN版本控制图标不显示的解决方法~

    新系统每次装了svn之后,过了一段时间,安装的软件一多就会出现这个问题,哎,收录一下解决方案! 输入:win+R,输入regedit,调出注册表信息,按下Ctrl+F,在注册表里搜索"She ...

  7. Android开发系列----学习伊始

    因为对移动端开发开始感兴趣,开始学习App开发,没有苹果环境的我,只好先选择Android来玩一玩了~~ 找了一套视频,买了几本java.android开发的书,开始搞起~~

  8. free 堡垒机

    环境: centos6.5 mini安装 iptables selinux已经关闭 jumpserver: 192.168.1.209 testserver: 192.168.1.210 一. 部署l ...

  9. jQuery api 学习笔记(1)

      之前自己的jquery知识库一直停留在1.4的版本,而目前jquery的版本已经更新到了1.10.2了,前天看到1.10中css()竟然扩充了那么多用法,这2天就迫不及待的更新一下自己的jquer ...

  10. 利用C#的反射机制动态调用DLL类库

    最近由于业务要求,需要动态调用DLL类库,所以研究了一下,感觉还好也不太难,今天就把自己理解的写了一个小例子(已经通过VS2005跑通),供大家一起研究和探讨,有理解不当的地方还请高手们多多指正,谢谢 ...