LightOJ - 1058

题意:给定n个顶点和其坐标,问这n个顶点里挑四个能组成几个平行四边形

Sample Input

2

6

0 0

2 0

4 0

1 1

3 1

5 1

7

-2 -1

8 9

5 7

1 1

4 8

2 0

9 8

Sample Output

Case 1: 5

Case 2: 6

思路:

我过于愚蠢。 判断平行四边形最简单的形式就是对角线相互平分,所以只要找出中点相同的点对就可以了。

/**

**/
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <set>
#define eps 1e-8
typedef long long ll;
const double PI = acos(-1.0);
const int maxn = 1e6;
const int INF = 0x3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+7;
using namespace std;
int n;
struct node
{
    int x,y;
}p1[maxn+5],p2[maxn+5];
bool judge(int a, int b)
{
    if(p2[a].x == p2[b].x && p2[a].y == p2[b].y)
        return 1;
    return 0;
}
bool cmp(node a, node b)
{
    if(a.x==b.x)
        return a.y<b.y;
    return a.x<b.x;
}
int main()
{
    //ios::sync_with_stdio(false);
    int T;
    scanf("%d",&T);
    int tt = 1;
    while(T--)
    {
        scanf("%d",&n);
        for(int i = 0; i<n; i++)
            scanf("%d %d",&p1[i].x,&p1[i].y);
        int k = 0;
        //计算所有不同点对的中点
        for(int i = 0; i<n; i++)
            for(int j = i+1; j<n; j++)
        {
            p2[k].x = (p1[i].x+p1[j].x);
            p2[k++].y = (p1[i].y+p1[j].y);
        }
        ll cnt = 1,ans = 0;
        sort(p2,p2+k,cmp);
        for(int i = 1; i<k; i++)
        {
            if(judge(i,i-1))
                cnt++;
            else
            {
                ans += (cnt-1)*cnt/2;
                cnt = 1;
            }
        }
        ans += (cnt-1)*(cnt)/2;
        printf("Case %d: %lld\n",tt++,ans);
    }

    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值