BZOJ_4004_[JLOI2015]装备购买_线性基
Description
Input
Output
一行两个数,第一个数表示能够购买的最多装备数量,第二个数表示在购买最多数量的装备的情况下的最小花费
Sample Input
1 2 3
3 4 5
2 3 4
1 1 2
Sample Output
HINT
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define eps 1e-6
typedef long double f2;
int n,m;
f2 a[510][510];
f2 fabs(f2 x){return x>0?x:-x;}
void Gauss() {
int i,j,k,mx;
f2 ans=0;
int cnt=0;
for(i=1;i<=m;i++) {
mx=0;
for(j=i;j<=n;j++) {
if(fabs(a[j][i])>eps) {
if(!mx) mx=j;
else if(a[j][m+1]<a[mx][m+1]) mx=j;
}
}
if(!mx) continue;
ans+=a[mx][m+1]; cnt++;
for(j=i;j<=m+1;j++) swap(a[i][j],a[mx][j]);
for(j=i+1;j<=n;j++) {
f2 tmp=-(a[j][i]/a[i][i]);
a[j][i]=0;
for(k=i+1;k<=m;k++) a[j][k]+=tmp*a[i][k];
}
}
printf("%d %.0Lf\n",cnt,ans);
}
int main() {
scanf("%d%d",&n,&m);
int i,j;
for(i=1;i<=n;i++) {
for(j=1;j<=m;j++) {
scanf("%Lf",&a[i][j]);
}
}
for(i=1;i<=n;i++) scanf("%Lf",&a[i][m+1]);
Gauss();
}