Luogu P3265 [JLOI2015] equipment purchase

Under a true sense of linear groups bare title

Usually we say about the linear main base in OI for binary, but here's the origin of the base linear regression, is based on a linear vector

We consider the binary-based algorithms for linear, it is mainly the number of broken down into a number of binary bits

Then each bit into the number corresponding to the number of erasing the back, mainly used is XOR

And what about the vector, we consider every vector into a corresponding vector, and then use this bit after this one to eliminate the current

So how to operate it, in fact, it is a Gaussian elimination process, so we come to the analogical way of general linear group structure

Then for this problem, we can think of greedy put equipment from small to large in value added, as if a set of vectors of linear correlation exists, then it is surely that will be deleted larger better

So this problem on done, there will be attention to accuracy cards, it proposed to openlong double

CODE

#include<cstdio>
#include<cmath>
#include<algorithm>
#define RI register int
#define CI const int&
using namespace std;
const int N=505;
const long double EPS=1e-6;
struct data
{
    long double mat[N]; int val;
    inline long double& operator [] (CI x) { return mat[x]; }
    friend inline bool operator < (const data& A,const data& B)
    {
        return A.val<B.val;
    }
}a[N]; int n,m,p[N],ans1,ans2;
int main()
{
    RI i,j,k; for (scanf("%d%d",&n,&m),i=1;i<=n;++i)
    for (j=1;j<=m;++j) scanf("%Lf",&a[i][j]);
    for (i=1;i<=n;++i) scanf("%d",&a[i].val);
    for (sort(a+1,a+n+1),i=1;i<=n;++i) for (j=1;j<=m;++j)
    {
        if (fabs(a[i][j])<EPS) continue;
        if (!p[j]) { p[j]=i; ++ans1; ans2+=a[i].val; break; }
        double dv=1.0*a[i][j]/a[p[j]][j];
        for (k=j;k<=m;++k) a[i][k]-=dv*a[p[j]][k];
    }
    return printf("%d %d",ans1,ans2),0;
}

Guess you like

Origin www.cnblogs.com/cjjsb/p/11111342.html