[P4736]大模拟WA求调
  • 板块灌水区
  • 楼主xxxalq
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/9/27 22:39
  • 上次更新2023/11/2 17:46:32
查看原帖
[P4736]大模拟WA求调
322437
xxxalq楼主2023/9/27 22:39

题目:P4736Assignment Algorithm

代码:

#include<iostream>
using namespace std;
int r,n,now=96,Left,Right,Row[55],maxidx;
char a[60][15];
const int inf=0x3f3f;
int check_door(){
	for(int i=1;i<=11;i++){
		if(a[2][i]=='-'){
			return 2;
		}
	}
	for(int i=1;i<=11;i++){
		if(a[r/2+3][i]=='-'){
			return r/2+3;
		}
	}
	return 0;
}
int Min(int x,int y,int z){
	return min(x,min(y,z));
}
int check_row(int x,int y){
	if(Row[x]>Row[y]){
		return x;
	}else if(Row[x]<Row[y]){
		return y;
	}
	if(Min(abs(x-1),abs(r+3-x),abs(r/2+2-x))<Min(abs(y-1),abs(r+3-y),abs(r/2+2-y))){
		return x;
	}else if(Min(abs(x-1),abs(r+3-x),abs(r/2+2-x))>Min(abs(y-1),abs(r+3-y),abs(r/2+2-y))){
		return y;
	}
	return min(x,y);
}
int check_line(int row){
	if(a[row][5]=='-'&&a[row][7]!='-'){
		return 5;
	}
	if(a[row][7]=='-'&&a[row][5]!='-'){
		return 7;
	}
	if(a[row][5]=='-'&&a[row][7]=='-'){
		return (Left<=Right?5:7);
	}
	//
	if(a[row][3]=='-'&&a[row][9]!='-'){
		return 3;
	}
	if(a[row][9]=='-'&&a[row][3]!='-'){
		return 9;
	}
	if(a[row][3]=='-'&&a[row][9]=='-'){
		return (Left<=Right?3:9);
	}
	//
	if(a[row][1]=='-'&&a[row][11]!='-'){
		return 1;
	}
	if(a[row][11]=='-'&&a[row][1]!='-'){
		return 11;
	}
	if(a[row][1]=='-'&&a[row][11]=='-'){
		return ((Left<=Right)?1:11);
	}
	//
	if(a[row][6]=='-'){
		return 6;
	}
	//
	if(a[row][2]=='-'&&a[row][10]!='-'){
		return 2;
	}
	if(a[row][10]=='-'&&a[row][2]!='-'){
		return 7;
	}
	if(a[row][2]=='-'&&a[row][10]=='-'){
		return (Left<=Right?2:10);
	}
}
int main(){
	scanf("%d%d",&r,&n);
	Row[0]=Row[1]=Row[r/2+2]=Row[r+3]=-inf;
	for(int i=1;i<=r+3;i++){
		for(int j=1;j<=11;j++){
			cin>>a[i][j];
			if(a[i][j]=='#'){
				if(j<6){
					Left+=1;
				}
				if(i>6){
					Right+=1;
				}
			}
			if(a[i][j]=='-'){
				Row[i]+=1;
			}
		}
	}
	while(n--){
		int door=check_door(),row;
		if(door){
			row=door;
		}else{
			maxidx=0;
			for(int i=1;i<=n;i++){
				maxidx=check_row(i,maxidx);
			}
			row=maxidx;
		}
		int line=check_line(row);
		a[row][line]=++now;
		Row[row]-=1;
		if(line<6){
			Left+=1;
		}
		if(line>6){
			Right+=1;
		}
		cout<<row<<" "<<line<<"\n";
	}
	for(int i=1;i<=r+3;i++){
		for(int j=1;j<=11;j++){
			cout<<a[i][j];
		}
		cout<<"\n";
	}
	return 0;
}
2023/9/27 22:39
加载中...