• 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;
    }
  • 相关阅读:
    机器学习常用算法
    判别式模型与生成式模型
    数据清洗方法
    机器学习项目流程清单
    免费的论文查重网站
    (转载)python应用svm算法过程
    opencv图像阈值设置的三种方法
    Tensorflow读取csv文件(转)
    tensorflow的数据输入
    为什么有些图像在显示前要除以255?(zhuan)
  • 原文地址:https://www.cnblogs.com/rainydays/p/2862173.html
Copyright © 2020-2023  润新知