ZOJ-1179

2 篇文章 0 订阅

矩形判断,先预排序一下,然后枚举所有四个点矩形组合判断下就行了

#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<iostream>

using namespace std;

namespace
{
	struct Point
	{
			char c;
			int x, y;
	};

	bool cmp(const Point *p1, const Point *p2)
	{
		if (p1->x != p2->x)
			return p1->x < p2->x;
		else
			return p1->y < p2->y;
	}

	bool valid(Point *p1, Point *p2, Point *p3, Point *p4)
	{
		return p1->x == p2->x && p3->x == p4->x && p1->y == p3->y
				&& p2->y == p4->y;
	}
}

int main()
{
	int n, x, y, count = 0;
	vector<Point*> V;
	vector<string> res;
	char s[2];
	while (scanf("%d", &n), n)
	{
		getchar();
		V.clear();
		res.clear();
		for (int i = 0; i < n; i++)
		{
			scanf("%s %d %d", s, &x, &y);
			Point *p = new Point();
			p->c = s[0];
			p->x = x;
			p->y = y;
			V.push_back(p);
		}
		sort(V.begin(), V.end(), cmp);
		for (size_t i = 0; i < V.size(); i++)
			for (size_t j = i + 1; j < V.size(); j++)
				for (size_t k = j + 1; k < V.size(); k++)
					for (size_t l = k + 1; l < V.size(); l++)
						if (valid(V[i], V[j], V[k], V[l]))
						{
							string str;
							str.push_back(V[j]->c);
							str.push_back(V[l]->c);
							str.push_back(V[k]->c);
							str.push_back(V[i]->c);
							res.push_back(str);
						}
		sort(res.begin(), res.end());
		printf("Point set %d:", ++count);
		if (res.size())
		{
			for (size_t i = 0; i < res.size(); i++)
			{
				if (i % 10 == 0)
					putchar('\n');
				cout << ' ' << res[i];
			}
			putchar('\n');
		}
		else
			puts(" No rectangles");
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值