CodeForces - 1086A/1085C

版权声明:博主的博客不值钱随便转载但要注明出处 https://blog.csdn.net/easylovecsdn/article/details/85229502

题意:

给出3个点,让你求出将3点连通的最小块数(临边相连为连通)

思路:
给个图就懂了,见下图

Code 

#include <bits/stdc++.h>

using namespace std;

struct Point {
	int x, y;
} p[3];

set<pair<int, int> > s;

bool cmp(Point p1, Point p2)
{
	if (p1.x == p2.x) return p1.y >= p2.y;
	return p1.x < p2.x;
}

int main()
{
	for (int i = 0; i < 3; i++) cin >> p[i].x >> p[i].y;
	sort(p, p + 3, cmp);
	
	for (int i = p[0].x; i <= p[1].x; i++) s.insert(make_pair(i, p[0].y));
	for (int i = min(p[0].y, min(p[1].y, p[2].y)); i <= max(p[0].y, max(p[1].y, p[2].y)); i++) s.insert(make_pair(p[1].x, i));
	for (int i = p[1].x + 1; i <= p[2].x; i++) s.insert(make_pair(i, p[2].y));

	set<pair<int, int> >::iterator it = s.begin();
	cout << s.size() << endl;
	while (it != s.end()) {
		cout << it->first << " " << it->second << endl;
		it++;
	}

	return 0;
}

猜你喜欢

转载自blog.csdn.net/easylovecsdn/article/details/85229502