70分求条
查看原帖
70分求条
894358
binomial楼主2024/8/21 10:20

rt. code:

#include <bits/stdc++.h>
using namespace std;
const double EPS=1e-3;
int n,m,cnt,ans;
struct l{
	vector<long double> b;
	int c;
}wjb[555],matrix[555];
void lb(l x){
	for(int i=m;i>=0;i--){
		if(x.b[i]>EPS||x.b[i]<-EPS){
			if(!wjb[i].c){
				wjb[i].c=1;
				cnt++;
				ans+=x.c;
				wjb[i].b=x.b;
				break;
			}
			else{
				long double d=x.b[i]/wjb[i].b[i];
				bool flag=0;
				for(int j=i;j>=0;j--){
					x.b[j]-=wjb[i].b[j]*d;
					if(x.b[j]>EPS){
						flag=1;
					}
				}
				if(!flag){
					break;
				}
			}
		} 
		
	}
}
bool cmp(l a,l b){
	return a.c<b.c;
}
int main(){
	scanf("%d%d",&n,&m);
	m--;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=m;j++){
			long double x;
			scanf("%Lf",&x);
			matrix[i].b.push_back(x);
		}
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&matrix[i].c);
	}
	sort(matrix+1,matrix+n+1,cmp);
	for(int i=1;i<=n;i++){
		lb(matrix[i]);
	}
	printf("%d %d",cnt,ans);
	return 0;
}
2024/8/21 10:20
加载中...