20分求助
  • 板块P1369 矩形
  • 楼主with_my_moon
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/5/24 20:55
  • 上次更新2024/5/24 21:00:15
查看原帖
20分求助
1112575
with_my_moon楼主2024/5/24 20:55
using namespace std;

int n;
int x1,x2;
int y1,y2;
int x1c,x2c,y1c,y2c;
int mx,my;

struct{
	int a,b;
}l[1000];

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
	cin>>l[i].a>>l[i].b;
	mx=max(l[i].a,mx);
	my=max(l[i].b,my);//存一下最大值
	}
	int count=0;
	for(int i=1;i<=mx;i++){
		for(int j=1;j<=n;j++){
			if(l[j].a==i) count++; 
		}
		if(count>x1c){
			x1c=count;
			x1=i;
		}
		else if(count>x2c){
			x2c=count;
			x2=i;
		}
		count=0;//找两条点最多的
	}
	count=0;
	for(int i=1;i<=my;i++){
		for(int j=1;j<=n;j++){
			if(l[j].b==i) count++; 
		}
		if(count>y1c){
			y1c=count;
			y1=i;
		}
		else if(count>y2c){
			y2c=count;
			y2=i;
		}
		count=0;//找两条点最多的
	}
	int ans=x1c+x2c+y1c+y2c;
	for(int i=1;i<=mx;i++){
		if(l[i].a==x1){
			if(l[i].b==y1) ans--;
			if(l[i].b==y2) ans--;
		}
		if(l[i].a==x2){
			if(l[i].b==y1) ans--;
			if(l[i].b==y2) ans--;
		}//有相交就减一
	}
	cout<<ans;
	return 0;	
}
2024/5/24 20:55
加载中...