bzoj3112

http://www.lydsy.com/JudgeOnline/problem.php?id=3112

模板题。。。模板又打错了。。。

#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
const double eps = 1e-8;
int n, m, l, e;
int p[N * 10];
double a[N][N * 10], b[N * 10][N];
void pivot(int l, int e)
{
    double r = a[l][e]; a[l][e] = 1.0;
    for(int i = 0; i <= n; ++i) a[l][i] /= r;
    p[0] = 0;
    for(int i = 0; i <= n; ++i) p[++p[0]] = i;
    for(int i = 0; i <= m; ++i) if(i != l && abs(a[i][e]) > eps)
    {
        double r = a[i][e]; a[i][e] = 0;
        for(int j = 1; j <= p[0]; ++j) a[i][p[j]] -= a[l][p[j]] * r;
    }
}
void simplex()
{
    while(true)
    {
        l = e = 0;
        for(int i = 1; i <= n; ++i) if(a[0][i] > eps) { e = i; break; }
        if(!e) break;
        double k = 1e18;
        for(int i = m; i; --i) if(a[i][e] > eps && a[i][0] / a[i][e] < k)
        { k = a[i][0] / a[i][e]; l = i; }
        if(!l) return;
        pivot(l, e);
    }
    printf("%d", (int)(-a[0][0] + 0.5));
}
int main()
{
//  freopen("zjoi13_defend.in", "r", stdin);
//  freopen("zjoi13_defend.out", "w", stdout);
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i) scanf("%lf", &b[0][i]);
    for(int i = 1; i <= m; ++i)
    {
        int l, r; scanf("%d%d%lf", &l, &r, &b[i][0]);
        for(int j = l; j <= r; ++j) b[i][j] += 1.0;
    }
    swap(n, m);
    for(int i = 0; i <= m; ++i) 
        for(int j = 0; j <= n; ++j) a[i][j] = b[j][i];
    simplex();
//  fclose(stdin); fclose(stdout);  
    return 0;   
}
View Code

 

posted @ 2017-05-14 14:20  19992147  阅读(136)  评论(0编辑  收藏  举报