• BZOJ3112 [Zjoi2013]防守战线 【单纯形】


    题目链接

    BZOJ3112

    题解

    同志愿者招募
    费用流神题
    单纯形裸题
    (BZOJ)可过
    洛谷被卡。。

    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<cstdio>
    #include<ctime>
    #include<cmath>
    #include<map>
    #define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
    #define REP(i,n) for (int i = 1; i <= (n); i++)
    #define mp(a,b) make_pair<int,int>(a,b)
    #define cls(s) memset(s,0,sizeof(s))
    #define cp pair<int,int>
    #define LL long long int
    using namespace std;
    const int maxn = 1005,maxm = 10005;
    const double eps = 1e-8,INF = 1e15;
    inline int read(){
    	int out = 0,flag = 1; char c = getchar();
    	while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
    	while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
    	return out * flag;
    }
    int n,m;
    double a[maxm][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 (i != l && fabs(a[i][e]) > eps){
    		t = a[i][e]; a[i][e] = 0;
    		for (int j = 0; j <= n; j++)
    			a[i][j] -= a[l][j] * t;
    	}
    }
    void init(){
    	while (true){
    		int l = 0,e = 0;
    		for (int i = 1; i <= m; i++) if (a[i][0] < -eps && (!l || (rand() & 1))) l = i;
    		if (!l) break;
    		for (int j = 1; j <= n; j++) if (a[l][j] < -eps && (!e || (rand() & 1))) e = j;
    		Pivot(l,e);
    	}
    }
    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(){
    	srand(time(NULL));
    	n = read(); m = read(); int L,R;
    	REP(j,n) a[0][j] = -read();
    	REP(i,m){
    		L = read(); R = read();
    		for (int j = L; j <= R; j++)
    			a[i][j] = -1;
    		a[i][0] = -read();
    	}
    	init(); simplex();
    	printf("%lld
    ",(LL)(a[0][0] + 0.5));
    	return 0;
    }
    
    
  • 相关阅读:
    uni-app 版本更新控制
    Chrome为什么打开一个页面,会有4个进程?
    vue 导航栏滚动吸顶
    vue 运行后, sass 报错
    HAProxy——HAProxy、Nginx、LVS优势劣势 (转)
    HAProxy——关于配置的备份
    RabbitMQ——用HAProxy实现负载均衡
    docker——Docker常见问题总结 (转)
    docker——docker容器内存和CPU使用限制
    docker——用docker-compose安装redis
  • 原文地址:https://www.cnblogs.com/Mychael/p/9249404.html
Copyright © 2020-2023  润新知