站外题未知原因CE求助
  • 板块学术版
  • 楼主Infinite_Energy
  • 当前回复18
  • 已保存回复18
  • 发布时间2023/8/19 15:09
  • 上次更新2023/11/3 02:41:14
查看原帖
站外题未知原因CE求助
561529
Infinite_Energy楼主2023/8/19 15:09

lz PKU 2195 的代码如下:

#include<iostream>
using namespace std;
long long n,m,w[110][110],cnt,cnt1,cnt2,march[110],va[110],vb[110],la[110],lb[110],delta;
char ch[110][110];
struct node{
	long long x,y;
}pos1[110],pos2[110];
long long abs_(long long x){
	if(x>=0){
		return x;
	}else{
		return -x;
	}
}
bool dfs(long long x){
	va[x]=1;
	for(int y=1;y<=cnt;y++){
		if(vb[y]==0){
			if(la[x]+lb[y]-w[x][y]==0){
				vb[y]=1;
				if(march[y]==0||dfs(march[y])==1){
					march[y]=x;
					return true;
				}
			}else{
		        delta=min(delta,la[x]+lb[y]-w[x][y]);
		    }
		}
	}
	return false;
}
long long KM(){
	long long ans=0;
	for(int i=1;i<=cnt;i++){
		la[i]=-1e18;
		lb[i]=0;
		for(int j=1;j<=cnt;j++){
			la[i]=max(la[i],w[i][j]);
		}
	}
	for(int i=1;i<=cnt;i++){
		while(1){
		    for(int j=1;j<=cnt;j++){
			    va[j]=0;
			    vb[j]=0;
		    }
			delta=1e18;
			if(dfs(i)==1){
				break;
			}
			for(int j=1;j<=cnt;j++){
				if(va[j]!=0){
					la[j]-=delta;
				}
				if(vb[j]!=0){
					lb[j]+=delta;
				}
			}
		}
	}
	for(int i=1;i<=cnt;i++){
		ans+=w[march[i]][i];
	}
	return ans;
}
int main(){
	while(cin>>n>>m){
		if(n==0&&m==0){
			break;
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				cin>>ch[i][j];
				if(ch[i][j]=='H'){
					cnt1++;
					pos1[cnt1].x=i;
					pos1[cnt1].y=j;
				}
				if(ch[i][j]=='m'){
					cnt2++;
					pos2[cnt2].x=i;
					pos2[cnt2].y=j;
				}
			}
		}
		cnt=cnt1;
		for(int i=1;i<=cnt;i++){
			for(int j=1;j<=cnt;j++){
				w[i][j]=abs_(pos1[i].x-pos2[j].x)+abs_(pos1[i].y-pos2[j].y);
				w[i][j]=-w[i][j];
			}
		}
		cout<<-(KM())<<endl;
		for(int i=1;i<=cnt;i++){
			pos1[i].x=0;
			pos1[i].y=0;
			pos2[i].x=0;
			pos2[i].y=0;
			march[i]=0;
			for(int j=1;j<=cnt;j++){
				w[i][j]=0;
			}
		}
		cnt1=0;
		cnt2=0;
		cnt=0;
	}
	return 0;
}

于 vjudge 提交此题并使用 C++98 (MinGW GCC 4.4.0) 语言后返回信息如下:

ld.exe: final link failed: No space left on device
collect2: ld returned 1 exit status

并且换用多种语言无果。求助。

2023/8/19 15:09
加载中...