zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    JavaScript中循环的使用方法
    认识了解JavaScript
    div的对齐显示
    四宫格div
    使用div写一个计算机
    div基本操作
    CSS样式
    Electron的逆向
    Electron输出:Hello,World
    Electron的安装-Windows
  • 原文地址:https://www.cnblogs.com/rainydays/p/2862173.html
Copyright © 2011-2022 走看看