bzoj 4004 向量拟阵

时间:2024-11-10 12:37:26

题解RT.

eps = 1e-10 WrongAnswer

eps = 1e-5 Accepted

 /**************************************************************
Problem: 4004
User: idy002
Language: C++
Result: Accepted
Time:516 ms
Memory:2844 kb
****************************************************************/ #include <cstdio>
#include <cstring>
#include <algorithm>
#define eps 1e-5
#define N 510
using namespace std; int n, m;
double aa[N][N];
int cost[N];
int vid[N];
int kid[N]; int sg( double x ) {
return (x>-eps)-(x<eps);
}
bool cmp( int a, int b ) { return cost[a]<cost[b]; }
bool join( int id ) {
for( int i=; i<=m; i++ ) {
if( sg(aa[id][i])== ) continue;
if( kid[i]== ) {
kid[i]=id;
return true;
}
int uid = kid[i];
double k = aa[id][i]/aa[uid][i];
for( int j=i; j<=m; j++ )
aa[id][j] -= k*aa[uid][j];
}
return false;
}
int main() {
scanf( "%d%d", &n, &m );
for( int i=; i<=n; i++ )
for( int j=; j<=m; j++ )
scanf( "%lf", &aa[i][j] );
for( int i=; i<=n; i++ )
scanf( "%d", cost+i );
for( int i=; i<=n; i++ )
vid[i] = i;
sort( vid+, vid++n, cmp );
memset( kid, , sizeof(kid) );
int cnt=, ans=;
for( int i=; i<=n; i++ ) {
int id = vid[i];
if( join(id) ) {
cnt++;
ans+=cost[id];
}
}
printf( "%d %d\n", cnt, ans );
}