ZOJ-1179

来源:互联网 发布:地址栏js执行 编辑:程序博客网 时间:2024/06/06 11:41

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

#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;elsereturn 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');}elseputs(" No rectangles");}return 0;}


0 0
原创粉丝点击