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

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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值