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. frame模型

    #import "CZWeiboFrame.h" #import "CZWeibo.h" @implementation CZWeiboFrame #defin ...

  2. java读取redis的timeout异常

    http://blog.csdn.net/shuaiokshuai/article/details/23266091 FIFO Fist-in Fisrt-out 先进先出

  3. ASP.NET Webform或者ASP.NET MVC站点部署到IIS下,默认情况下.json文件是不能被访问的,如果请求访问.json文件,则会出现找不到文件的404错误提示

    解决方法 <system.webServer> <staticContent> <remove fileExtension=".woff" /> ...

  4. (转)javaScript call 函数的用法说明

    call 方法 请参阅 应用于:Function 对象 要求 版本 5.5 调用一个对象的一个方法,以另一个对象替换当前对象. call([thisObj[,arg1[, arg2[, [,.argN ...

  5. jsp-文件的上传(转).

    该程序的主要代码,我引用网友的,并做了一些改进.上这个帖子的原因之一,是为了修正之前自己的一些误解. 概述: 一些网友,包括我,也曾经试图通过 input type 为 file的控件,获取其文件的完 ...

  6. EntityFrameowk6.1 使用enum和低版本的不同

    原有项目中使用EF5.0 实体类 public partial class Log : BaseEntity { public Nullable<int> LogLevelId { get ...

  7. 网站如何防Session冒名顶替和cookie防篡改

    做网站难免要面对安全性的问题,诸如sql注入拉,cookie冒名拉,等等,sql注入算是老生常谈,翻翻旧账有不少优秀的帖子在说明这个问题,所以我们来说说Session冒名顶替的风险以及应对的办法. 首 ...

  8. ValidationContext

    .NET 4 和Silverlight 中可以使用以下方法: ? public static void Validate(this Entity entity) {     // prepare th ...

  9. Android学习笔记(广播机制)

    1.Android的广播机制介绍 收听收音机也是一种广播,在收音机中有很多个广播电台,每个广播电台播放的内容都不相同.接受广播时广播(发送方)并不在意我们(接收方)接收到广播时如何处理.好比我们收听交 ...

  10. 解决UITabeleViewCell的分割线不能铺满问题

    -(void)viewDidLayoutSubviews { if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)] ...