UVA10498 Happiness "simplex"

Source: Internet
Author: User

Topic links

UVA10498

Exercises

Template questions

#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,in    T 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 "simplex"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.