zoukankan      html  css  js  c++  java
  • Bzoj4004: [JLOI2015]装备购买

    题面

    传送门

    Sol

    很像线性基

    其实就是线性基
    我一直以为它只能搞异或
    线性基解决异或问题时是怎么插入的?
    就像高斯消元一样,如果这里有值,就进行消元
    否则直接加入

    那么这个题也可以如此,只是把异或改成减法
    这样我们就把高斯消元和线性基结合起来了

    # include <bits/stdc++.h>
    # define RG register
    # define IL inline
    # define Fill(a, b) memset(a, b, sizeof(a))
    using namespace std;
    typedef long long ll;
    typedef long double lod;
    
    template <class Int>
    IL void Input(RG Int &x){
        RG int z = 1; RG char c = getchar(); x = 0;
        for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
        for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
        x *= z;
    }
    
    const int maxn(505);
    const lod EPS(1e-5);
    
    int n, m, c[maxn], id[maxn], ans1, ans2, vis[maxn];
    lod a[maxn][maxn], w[maxn][maxn];
    
    IL int Cmp(RG int x, RG int y){
    	return c[x] < c[y];
    }
    
    IL int Check(RG int x){
    	for(RG int i = 1; i <= m; ++i)
    		if(fabs(w[x][i]) > EPS){
    			if(!vis[i]){
    				vis[i] = 1;
    				for(RG int j = 1; j <= m; ++j) a[i][j] = w[x][j];
    				return 1;
    			}
    			else{
    				RG lod div = w[x][i] / a[i][i];
    				for(RG int j = i; j <= m; ++j) w[x][j] -= a[i][j] * div;
    			}
    		}
    	return 0;
    }
    
    int main(RG int argc, RG char* argv[]){
    	Input(n), Input(m);
    	for(RG int i = 1; i <= n; ++i)
    		for(RG int j = 1, t; j <= m; ++j)
    			Input(t), w[i][j] = t;
    	for(RG int i = 1; i <= n; ++i) Input(c[i]), id[i] = i;
    	sort(id + 1, id + n + 1, Cmp);
    	for(RG int p = 1, i; p <= n; ++p)
    		if(Check(i = id[p])) ++ans1, ans2 += c[i];
    	printf("%d %d
    ", ans1, ans2);
        return 0;
    }
    
  • 相关阅读:
    分享图片到在线服务
    获取和保存照片
    处理图片(updated)
    简化版“询问用户是否退出”
    捕获高像素照片(updated)
    处理高像素的照片
    加强版照片捕获
    图片拍摄、处理、镜头应用
    Windows Phone 推送通知的第四类推送
    网络通信
  • 原文地址:https://www.cnblogs.com/cjoieryl/p/8805010.html
Copyright © 2011-2022 走看看