zoukankan      html  css  js  c++  java
  • UVA 10574

    Given n points on the XY plane, count how many regular rectangles are formed. A rectangle is regular if and only if its sides are all parallel to the axis.
    Input
    The first line contains the number of tests t (1 ≤ t ≤ 10). Each case contains a single line with a
    positive integer n (1 ≤ n ≤ 5000), the number of points. There are n lines follow, each line contains 2
    integers x, y (≤ x, y ≤ 109
    ) indicating the coordinates of a point.
    Output
    For each test case, print the case number and a single integer, the number of regular rectangles found.
    Sample Input
    2
    5
    0 0
    2 0
    0 2
    2 2
    1 1
    3
    0 0
    0 30
    0 900
    Sample Output
    Case 1: 1
    Case 2: 0

    题意:给你n个点 ,问你这些点能够组成多少个 长宽和坐标轴平行的 矩形

    题解:按照x排序,在y轴平行下,选择不同直线组合,满足两y轴上的点相等就是一种,  对于一堆相等的 我们用组合数就好了

    //meek
    ///#include<bits/stdc++.h>
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <string>
    #include <cstring>
    #include <algorithm>
    using namespace std ;
    typedef long long ll;
    #define mem(a) memset(a,0,sizeof(a))
    #define pb push_back
    #define fi first
    #define se second
    #define MP make_pair
    
    const int N=5005;
    const ll INF = 1ll<<61;
    const int inf = 1<<31;
    const int mod= 1000000007;
    const int M = 1000000;
    
    
    struct ss{
      int x,y;
    }a[N],p[N*N];
    int cnt;
    int cmp(ss s1,ss s2) {
        if(s1.x == s2.x) return s1.y<s2.y;
        return s1.x<s2.x;
    }
    void init() {
      cnt = 0;mem(p);
    }
    ll solve() {
        ll ans = 0;
      for(int i = 0;i < cnt; ) {
        int now = i+1;
        while(p[i].x == p[now].x && p[i].y == p[now].y) now++;
        ll c = now - i;
        if(c>=2) ans += c*(c-1)/2;
        i = now;
      }
      return ans;
    }
    int main() {
        int T,n,x,y,cas = 1;
        scanf("%d",&T);
        while(T--) {
            init();
            scanf("%d",&n);
            for(int i=1;i<=n;i++) {
                scanf("%d%d",&x,&y);
                a[i].x = x;
                a[i].y = y;
            }
            sort(a+1,a+n+1,cmp);
            cnt = 0;
            for(int i=1;i<=n;i++) {
                for(int j=i+1;j<=n;j++) {
                    if(a[i].x != a[j].x) {
                       break; 
                    }
                    p[cnt].x = a[i].y;
                    p[cnt].y = a[j].y;
                    cnt++;
                }
            }
            printf("Case %d: ",cas++);
            sort(p,p+cnt,cmp);
            printf("%lld
    ",solve());
        }
        return 0;
    }
    代码
  • 相关阅读:
    Python—使用列表构造队列数据结构
    js数组及对象去重
    当z-index遇上transform
    echarts y轴百分比显示
    在vue-cli项目中使用echarts
    IE中在a标签里的图片会显示边框
    css 三种清除浮动(float)的方法
    js技巧
    深入理解 函数、匿名函数、自执行函数
    即时反应的input和propertychange方法
  • 原文地址:https://www.cnblogs.com/zxhl/p/5095050.html
Copyright © 2011-2022 走看看