UVA10498 Happiness 【單純形】

來源:互聯網
上載者:User

標籤:size   ems   return   ring   sizeof   max   for   nas   std   

題目連結

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 【單純形】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.