P3265 [JLOI2015]装备购买 —— 线性基

本文介绍了一种在实数域中处理矩阵的算法,涉及线性基的定义、插入操作的高效实现,以及如何通过快速排序和动态调整系数矩阵来解决特定问题。重点在于如何通过比较节点权重并优化插入过程,以求解具有特定结构的矩阵问题。
摘要由CSDN通过智能技术生成

Link
实数下线性基

#define double long double
double a[N][N];
struct node {
    double a[550];
    int w;
    bool operator < (const node &x) const {
        return w < x.w;
    }
}p[550];
int n, m;
double b[N][N];
bool insert(int m, double c[]) {
    for(int i = m-1; i >= 0; i--) {
        if(fabs(c[i]) < EPS) continue;
        if(fabs(b[i][i]) < EPS) {
            for(int j = 0; j < m; j++)
                b[i][j] = c[j];
            return true;
        }
        double t = c[i]/b[i][i];
        for(int j = 0; j < m; j++)
            if(fabs(c[i]) > EPS)
                c[j] -= b[i][j] * t;
    }
    return false;
}
void solve() {
    cin >> n >> m;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            cin >> p[i].a[j];
    for(int i = 0; i < n; i++)
    {
        cin >> p[i].w;
        p[i].a[m] = p[i].w;
    }
    sort(p, p + n);
    int cnt = 0, res = 0;
    for(int i = 0; i < n; i++) {
        if(insert(m, p[i].a)) {
            cnt++;
            res += p[i].w;
        }
    }
    cout << cnt << ' ' << res << endl;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值