博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数学(线性规划):UVAoj 10498 Happiness
阅读量:4330 次
发布时间:2019-06-06

本文共 3536 字,大约阅读时间需要 11 分钟。

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.      这是线性规划模版题。
1 #include 
2 #include
3 #include
4 #include
5 const double EPS = 1e-10; 6 const int MAXN = 55; 7 const int INF = 0x3fff3fff; 8 9 inline int sgn(double x) {10 return (x>EPS)-(x<-EPS);11 }12 13 double A[MAXN][MAXN];14 double b[MAXN],c[MAXN];15 int N[MAXN],B[MAXN];16 int n,m;17 double v;18 19 bool init() {20 N[0]=B[0]=v=0;21 for(int i=1;i<=n;++i)N[++N[0]]=i;22 for(int i=1;i<=m;++i)B[++B[0]]=n+i;23 return true;24 }25 26 void pivot(int l,int e){27 b[e]=b[l]/A[l][e];28 A[e][l]=1.0/A[l][e];29 for(int i=1;i<=N[0];++i){30 int &x=N[i];31 if(x!=e)A[e][x]=A[l][x]/A[l][e];32 }33 for(int i=1;i<=B[0];++i)if(B[i]!=){34 int y=B[i];35 b[y]-=A[y][e]*b[e];36 A[y][l]=-A[y][e]*A[e][l];37 for(int j=1;j<=N[0];++j){38 int x=N[j];39 if(x!=e)A[y][x]-=A[e][x]*A[y][e];40 }41 }42 v+=b[e]*c[e];43 c[l]=-A[e][l]*c[e];44 for(int i=1;i<=N[0];++i) {45 int x=N[i];46 if(x!=e)c[x]-=A[e][x]*c[e];47 }48 for(int i=1;i<=N[0];++i)if(N[i]==e)N[i]=l;49 for(int i=1;i<=B[0];++i)if(B[i]==l)B[i]=e;50 }51 52 bool simplex() {53 while(true) {54 int e=MAXN;55 for(int i=1;i<=N[0];++i) {56 int x=N[i];57 if(sgn(c[x])>0&&x
0){65 double tmp=b[y]/A[y][e];66 if(delta==-1||sgn(tmp-delta)<0||(sgn(tmp-delta)==0&&y

 

转载于:https://www.cnblogs.com/TenderRun/p/5615298.html

你可能感兴趣的文章
Endnote--修改参考文献在word引文处的格式
查看>>
在TCGA中查找mutation突变
查看>>
甲基化会随着年龄动态变化吗?
查看>>
文献--用测序和基因组方法研究神经性疾病
查看>>
python的多线程+GIL全局解释器锁+其他LOCK
查看>>
深浅copy Python DAY3
查看>>
python多线程+GIL
查看>>
Laravel从模型中图片的相对路径获取绝对路径
查看>>
Laravel 里最简单的CURD套路
查看>>
Laravel NPM包的使用
查看>>
Laravel-Admin图片上传时的问题
查看>>
git升级与报错问题
查看>>
Thinkphp 使用小结
查看>>
Laravel注册登陆认证API
查看>>
大文件上传不了一般有哪些原因?
查看>>
js正则先行断言,
查看>>
webstorm编写html,浏览器浏览时,端口号固定
查看>>
Kafka集群部分参数配置
查看>>
封锁阳光大学
查看>>
字典树模板
查看>>