ZOJ-1179
2014-07-19 11:19
281 查看
矩形判断,先预排序一下,然后枚举所有四个点矩形组合判断下就行了
#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; }
相关文章推荐
- zoj 1179 Finding Rectangles
- ZOJ 1179 Finding Rectangles(DFS+剪枝)
- zoj 2704 dp
- zoj 2316 Matrix Multiplication(2-D)
- ZOJ 3329 One Person Game 带环的概率DP
- ZOJ 3710 Friends
- ZOJ 3203 Light Bulb
- zoj 2369 Two Cylinders
- zoj 2949 - Coins of Luck
- ZOJ 3752 The Three Guys(暴力)
- ZOJ 3077 记忆化动态规划
- hdu 1051/zoj 1025 贪心问题
- ZOJ 3662 dp+映射表
- ZOJ 3715 Kindergarten Election
- zoj1504Slots of Fun
- ZOJ1542 POJ1861
- ZOJ 3818 Pretty Poem The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- ZOJ 1760
- ZOJ 1298 Domino Effect(POJ1135)(最短路)
- POJ 2418 ,ZOJ 1899 Hardwood Species - from lanshui_Yang