zoukankan      html  css  js  c++  java
  • uva 10574

    版权声明:本文为博主原创文章,未经博主同意不得转载。

    https://blog.csdn.net/u011328934/article/details/27520895

    题目链接:uva 10574 - Counting Rectangles

    题目大意:给出n个点。问选出4个点作为定点,能够组成多少个平行与坐标轴的矩形。

    解题思路:首先将点依照x排序(优化),然后处理出全部平行于y轴的线段,记录这些线段的y1和y2,接着仅仅要找出y1和y2值均相等的边,C(2cnt).

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    
    using namespace std;
    typedef long long ll;
    const int N = 5005;
    
    struct point {
        int x, y;
        void get () {
            scanf("%d%d", &x, &y);
        }
        void set (int x, int y) {
            this->x = x;
            this->y = y;
        }
    }p[N], l[N*N/2];
    int n, m;
    
    inline bool cmp(const point& a, const point& b) {
        if (a.x != b.x)
            return a.x < b.x;
        return a.y < b.y;
    }
    
    void init () {
        scanf("%d", &n);
        for (int i = 0; i < n; i++)
            p[i].get();
    
        sort(p, p + n, cmp);
    
        m = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                if (p[i].x != p[j].x)
                    break;
    
                l[m++].set(p[i].y, p[j].y);
            }
        }
        sort(l, l + m, cmp);
    }
    
    ll solve () {
        ll ans = 0;
    
        for (int i = 0; i < m;) {
            int mv = i+1;
    
            while (l[i].x == l[mv].x && l[i].y == l[mv].y)
                mv++;
    
            ll c = mv - i;
    
            if (c >= 2)
                ans += c * (c - 1) / 2;
            i = mv;
        }
        return ans;
    }
    
    int main () {
        int cas;
        scanf("%d", &cas);
        for (int i = 1; i <= cas; i++) {
            init();
            printf("Case %d: %lld
    ", i, solve());
        }
        return 0;
    }
查看全文
  • 相关阅读:
    搭建selenium+python自动化环境
    编写函数计算一个数字的长度
    编写函数digit(num, k),函数功能是:求整数num从右边开始的第k位数字的值,如果num位数不足k位则返回0。
    求m-n之间数字的和
    编写一个函数,生成4位数字的验证码
    编写一个函数,在页面上输出一个N行M列的表格,表格内容填充0~100的随机数字
    编写一个函数,计算三个数字的大小,按从小到大的顺序输出
    编写函数,判断一个字符串的内容是不是纯数字
    编写函数,求圆的面积
    编写一个函数,计算两个数字的和差积商
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10746717.html
  • Copyright © 2011-2022 走看看