当前位置: 首页 > 工具软件 > Eurasia > 使用案例 >

2021-2022 ICPC, NERC, Northern Eurasia Onsite (Unrated, Online Mirror, ICPC Rules, Teams Preferred

罗梓
2023-12-01

2021-2022 ICPC, NERC, Northern Eurasia Onsite (Unrated, Online Mirror, ICPC Rules, Teams Preferred)

C. Connect the Points

题意:给你三个点,让你添加若干条平行于 x x x轴和 y y y轴的线段,让这三个点在一个连通块上,问在所有的方案中,所有添加的线段长度最小的方案。

思路:找到三个点横坐标大小位于中间的那个,令其为xm,找到纵坐标大小位于中间的那个,令其为ym,我们用平行 x x x轴和平行 y y y轴的线段把这三个点和 ( x m , y m ) (xm, ym) (xm,ym)连接在一起即可。

#include <bits/stdc++.h>
#define PII pair<int,int>
#define LL long long
#define fi first
#define debug(x) cout << #x << " = " << x << endl;
#define se second
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define sz(x) (int)x.size()
#define INF 2e9
#define mod 998244353

using namespace std;

int a, b, c, d, e, f;

struct Node{
	int x, y, a, b;
};
vector<Node>ans;

int main()
{
	cin >> a >> b >> c >> d >> e >> f;
	int mdx, mdy;
	vector<int>q;
	q.push_back(a), q.push_back(c), q.push_back(e);
	sort(all(q)); mdx = q[1];
	q.clear();
	q.push_back(b), q.push_back(d), q.push_back(f);	
	sort(all(q)); mdy = q[1];
	if(a != mdx && b != mdy){
		ans.pb({a, b, a, mdy});
		ans.pb({a, mdy, mdx, mdy});
	}else if(a == mdx){
		if(b != mdy){
			ans.pb({a, b, a, mdy});
		}
	}else if(b == mdy){
		if(a != mdx){
			ans.pb({a, b, mdx, mdy});
		}
	}
	a = c, b = d;
	if(a != mdx && b != mdy){
		ans.pb({a, b, a, mdy});
		ans.pb({a, mdy, mdx, mdy});
	}else if(a == mdx){
		if(b != mdy){
			ans.pb({a, b, a, mdy});
		}
	}else if(b ==  mdy){
		if(a != mdx){
			ans.pb({a, b, mdx, mdy});
		}
	}
	a = e, b = f;
	if(a != mdx && b != mdy){
		ans.pb({a, b, a, mdy});
		ans.pb({a, mdy, mdx, mdy});
	}else if(a == mdx){
		if(b != mdy){
			ans.pb({a, b, a, mdy});
		}
	}else if(b ==  mdy){
		if(a != mdx){
			ans.pb({a, b, mdx, mdy});
		}
	}
	cout << sz(ans) << '\n';
	for(auto it : ans){
		cout << it.a << " " << it.b << " " << it.x << " " << it.y << '\n';
	}
	cout << '\n';
	return 0;
}


 类似资料: