• poj1314


    枚举

    View Code
    #include<iostream>
    #include<algorithm>
    using namespace std;
    
    struct point
    {
        char ss;
        int x, y;
    };
    
    struct direction
    {
        char ul, ur, lr, ll;
    };
    
    direction dir[100];
    point p[30];
    int sum;
    
    int cmp(point a, point b)
    {
        if (a.x != b.x)
            return a.x < b.x;
        else
            return a.y < b.y;
    }
    
    int cmp_re(direction a, direction b)
    {
        if (a.ul != b.ul)
            return a.ul < b.ul;
        else
        {
            if (a.ur != b.ur)
                return a.ur < b.ur;
            else
            {
                if (a.lr != b.lr)
                    return a.lr < b.lr;
                else
                    return a.ll < b.ll;
            }
        }
    }
    
    bool work(int n)
    {
        int i, j, k, l;
        for (i = 0; i < n; ++i)
        {
            for (j = i + 1; j < n; ++j)
            {
                if (p[i].x == p[j].x)
                {
                    for (k = j + 1; k < n; ++k)
                    {
                        if (p[i].y == p[k].y)
                        {
                            for (l = k + 1; l < n; ++l)
                            {
                                if (p[j].y - p[i].y == p[l].y - p[k].y
    
                                && p[k].x - p[i].x == p[l].x - p[j].x)
                                {
                                    dir[sum].ul = p[j].ss, dir
    
                                    [sum].ur = p[l].ss;
                                    dir[sum].lr = p[k].ss, dir
    
                                    [sum].ll = p[i].ss;
                                    sum++;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (!sum)
            return false;
        else
            return true;
    }
    
    int main()
    {
        int i, n, cas = 1;
    // freopen("t.txt","r",stdin);
    // freopen("out.txt","w",stdout);
        while (cin >> n && n)
        {
            for (i = 0; i < n; ++i)
                cin >> p[i].ss >> p[i].x >> p[i].y;
            sort(p, p + n, cmp);
            sum = 0;
            cout << "Point set " << cas++ << ":";
            if (!work(n))
                cout << " No rectangles" << endl;
            else
            {
    
                cout << endl;
                sort(dir, dir + sum, cmp_re);
                for (i = 0; i < sum; ++i)
                {
                    cout << " " << dir[i].ul << dir[i].ur << dir[i].lr << dir[i].ll;
                    if ((i + 1) % 10 == 0 && i + 1 < sum)
                        cout << endl;
                }
                cout << endl;
            }
        }
        return 0;
    }
  • 相关阅读:
    postman使用感言
    20. 有效的括号
    13. 罗马数字转整数
    qsort / bsearch
    堆排序(heapsort)
    递归Recursion
    拓扑排序
    N/A的含义
    初级系列17.爱因斯坦的数学题问题
    初级系列16.求车速问题
  • 原文地址:https://www.cnblogs.com/rainydays/p/2862173.html
Copyright © 2020-2023  润新知