zoukankan      html  css  js  c++  java
  • LightOJ

    链接:

    https://vjudge.net/problem/LightOJ-1058

    题意:

    There are n distinct points in the plane, given by their integer coordinates. Find the number of parallelograms whose vertices lie on these points. In other words, find the number of 4-element subsets of these points that can be written as {A, B, C, D} such that AB || CD, and BC || AD. No four points are in a straight line.

    思路:

    考虑平行四边形,对角线的中点相交,所以枚举所有中点,相同的点组合数求解。
    map爆内存。。。

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<math.h>
    #include<vector>
    #include<map>
    #include<set>
    #include<utility>
    
    using namespace std;
    typedef long long LL;
    const int INF = 1e9;
    
    const int MAXN = 1e3+10;
    const int MOD = 1e9+7;
    
    struct Node
    {
        double x, y;
    }node[MAXN*MAXN];
    
    int n;
    int x[MAXN], y[MAXN];
    
    Node GetMid(int l, int r)
    {
        return Node{double(x[l]+x[r])/2.0, double(y[l]+y[r])/2.0};
    }
    
    bool Cmp(Node a, Node b)
    {
        if (a.x != b.x)
            return a.x < b.x;
        return a.y < b.y;
    }
    
    int main()
    {
        int cnt = 0;
        int t;
        scanf("%d", &t);
        while(t--)
        {
            printf("Case %d:", ++cnt);
            scanf("%d", &n);
            for (int i = 1;i <= n;i++)
                scanf("%d%d", &x[i], &y[i]);
            int tot = 0;
            for (int i = 1;i <= n;i++)
            {
                for (int j = i+1;j <= n;j++)
                {
                    node[++tot] = GetMid(i, j);
                }
            }
            int res = 0;
            sort(node+1, node+1+tot, Cmp);
            int tmp = 1;
            for (int i = 2;i <= tot;i++)
            {
                if (node[i].x == node[i-1].x && node[i].y == node[i-1].y)
                    tmp++;
                else
                {
                    if (tmp >= 2)
                        res += 1LL*tmp*(tmp-1)/2;
                    tmp = 1;
                }
                if (i == tot && tmp >= 2)
                    res += 1LL*tmp*(tmp-1)/2;
    
            }
            printf(" %d
    ", res);
        }
        
        return 0;
    }
    
  • 相关阅读:
    chrome 的 css hack
    WebService报用户名密码错误
    银行系统数据加密方法
    (转)让插入到 innerHTML 中的 script 跑起来
    JSP导出Excel
    简单使用JDOM解析XML 完整版 转
    IO流读取文件
    JSP下载服务器文件
    (转JAVAEYE)System类方法大全
    list 排序
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11886514.html
Copyright © 2011-2022 走看看