Educational Codeforces Round 11 _D

http://codeforces.com/contest/660/problem/D

这个题据说是很老的题了 然而我现在才知道做法

用map跑了1953ms;

题目大意 给你n个点的坐标 求这些点能组成多少个位置不同的四边形

我们统计两个点之间的中点坐标  假如有n对点的中点重合 那么我们就知道这里面有(n-1)*n/2个平行四边形

就这样搞喽。

PS:说实话typedef pair<double,double> pdd; 这语句让我想到了骚猪PDD 笑死了。

#include<cstdio>
#include<map>
//#include<bits/stdc++.h>
#include<vector>
#include<stack>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<cstdlib>
#include<climits>
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<double,double> pdd;
typedef __int64 int64;
const ll mood=1e9+7;
const int64 Mod=998244353;
const double eps=1e-9;
const int N=2e7+10;
const int MAXN=2050;
inline void rl(ll&num){
    num=0;ll f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
    num*=f;
}
inline void ri(int &num){
    num=0;int f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
    num*=f;
}
double a[MAXN],b[MAXN];
int main()
{
    int n;
    map<pdd,int>mp;
    ri(n);
    for(int i=0;i<n;i++)
    {
        scanf("%lf%lf",&a[i],&b[i]);
    }
    pdd x;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            x.first=(a[i]+a[j])/2;
            x.second=(b[i]+b[j])/2;
            mp[x]++;
        }
    }
    ll ans=0;
    map<pdd,int>::iterator it;
    for(it=mp.begin();it!=mp.end();++it)
    {
        int tem=it->second;
        pdd t=it->first;
        ans+=(tem-1)*tem/2;
    }
    cout<<ans<<endl;
    return 0;
}
一个古老的题
原文地址:https://www.cnblogs.com/Geek-xiyang/p/5404122.html