zoukankan      html  css  js  c++  java
  • UVA10498 Happiness 【单纯形】

    题目链接

    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.
    ",(LL)floor((-a[0][0]) * m + 1 - eps));
    	}
    	return 0;
    }
    
    
  • 相关阅读:
    pm3
    算法交易系列研究之一
    CDS究竟是个什么鬼?它直接导致了次贷危机?
    源特定组播(SSM:Source Specific Multicast)
    投资交易系统常用表
    交易系统解析(六)前台报盘应用设计要点
    人物
    句子
    康德拉季耶夫周期
    非标
  • 原文地址:https://www.cnblogs.com/Mychael/p/9270036.html
Copyright © 2011-2022 走看看