Number of Parallelograms CodeForces - 660D (几何)
Number of Parallelograms
You are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points.
Input
The first line of the input contains integer n (1 ≤ n ≤ 2000) — the number of points.
Each of the next n lines contains two integers (x**i, y**i) (0 ≤ x**i, y**i ≤ 109) — the coordinates of the i-th point.
Output
Print the only integer c — the number of parallelograms with the vertices at the given points.
Example
Input
40 11 01 12 0
Output
1
题意:
给你n个互不相同的点,且没3个点在一条直线上。
问你这n个点能组成多少个不同的平行四边形。
思路:
因为没3个点在一条直线上,所以不存在两个平行四边形的中心点(对角线的交点)在同一点。
所以我们可以n*n枚举任意两个点,把这两点当作一个平行四边行的对角线,计算他的中心,如果有其他线的中心也是这个点,那么这2个对角线的4个点可以构成一个平行四边形。
我们可以用map来维护每一个中点出现的个数,依次计算出答案。
ps:因为计算两个点的中点过程中/2这一步会出现小数,所以我没/2,而是直接默认全是中点坐标是*2的。不影响答案的计算。
如果不保证三点共线就不能这样做,
因为会有这种情况:

细节见代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {a %= MOD; if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline void getInt(int *p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
struct point {
    int x, y;
    point()
    {
    }
    point (int _x, int _y)
    {
        x = _x;
        y = _y;
    }
    point operator - (const point &b) const
    {
        return point(x - b.x, y - b.y);
    }
    point operator + (const point &b) const
    {
        return point(x + b.x, y + b.y);
    }
    bool operator < (const point &b) const
    {
        pii t1 = mp(x, y);
        pii t2 = mp(b.x, b.y);
        return t1 < t2;
    }
    void P()
    {
        cout << x << " " << y << endl;
    }
};
map<point, int> m;
point a[maxn];
int main()
{
    //freopen("D:\\code\\text\\input.txt","r",stdin);
    //freopen("D:\\code\\text\\output.txt","w",stdout);
    int n;
    gbtb;
    cin >> n;
    repd(i, 1, n) {
        cin >> a[i].x >> a[i].y;
    }
    point v;
    int ans = 0;
    repd(i, 1, n) {
        repd(j, i + 1, n) {
            v = a[i] + a[j];
            ans += m[v];
            m[v]++;
        }
    }
    cout << ans  << endl;
    return 0;
}
inline void getInt(int *p)
{
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    } else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}
												
											Number of Parallelograms CodeForces - 660D (几何)的更多相关文章
- codeforces 660D D. Number of Parallelograms(计算几何)
		
题目链接: D. Number of Parallelograms time limit per test 4 seconds memory limit per test 256 megabytes ...
 - 【CodeForces 660D】Number of Parallelograms(n个点所能组成的最多平行四边形数量)
		
You are given n points on a plane. All the points are distinct and no three of them lie on the same ...
 - Educational Codeforces Round 11 D. Number of Parallelograms 暴力
		
D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...
 - Number of Parallelograms(求平行四边形个数)
		
Number of Parallelograms time limit per test 4 seconds memory limit per test 256 megabytes input sta ...
 - D. Number of Parallelograms
		
D. Number of Parallelograms 原题链接 time limit per test 4 seconds memory limit per test 256 megabytes Y ...
 - D. Number of Parallelograms 解析(幾何)
		
Codeforce 660 D. Number of Parallelograms 解析(幾何) 今天我們來看看CF660D 題目連結 題目 給你一些點,求有多少個平行四邊形. 前言 @copyrig ...
 - CodeForces 660D Number of Parallelograms
		
枚举两点,确定一条线段,计算每条线段的中点坐标. 按线段中点坐标排个序.找出每一种坐标有几个. 假设第x种坐标有y个,那么这些线段可以组成y*(y-1)/2种平行四边形. 累加即可. #include ...
 - CodeForces - 660D:Number of Parallelograms (问N个点多少个平行四边形)
		
pro:给定N个点,问多少个点组成了平行四边形.保证没有三点共线. sol:由于没有三点贡献,所以我们枚举对角线,对角线的中点重合的就是平行四边形.如果没说保证三点不共线就不能这么做,因为有可能4个点 ...
 - codeforce 660D  Number of Parallelograms
		
题意:询问多少个矩形. 统计横纵坐标差,放进vector中 #include<cstdio> #include<cstring> #include<iostream> ...
 
随机推荐
- centos 自动挂载ISO
			
创建挂载点并挂载光盘mkdir -p /media/cdrommount -t iso9660 -o loop /usr/ison/centos.iso /media/cdrom 设置开机自动挂载:方 ...
 - ForeFront TMG标准版
			
ForeFront TMG 标准版安装指南 目前 Forefonrt TMG 的RTM版本已经正式发布,你可以在 ISA中文站上下载120天测试版本: http://www.isacn.org/inf ...
 - PHP学习(2)——操作符与迭代整理
			
目录: 10.操作符整理 11.表单计算代码 12.优先级与结合性 13.可变函数 14.条件判断 15.循环迭代 16.跳出控制 17.可替换的控制结构 10.操作符 10.1 算术操作符 算术操作 ...
 - code review规则
			
简单可行的code review规则 前言 曾经有一段垃圾代码放在我的面前,我没有拒绝,等我真正开始接手的时候我才后悔莫及,程序员最痛苦的事莫过于此! 每当接手别人的代码,都有一种想重新写一遍的感觉, ...
 - 小记--------spark的Master的Application注册机制源码分析及Master的注册机制原理分析
			
原理图解: Master类位置所在:spark-core_2.11-2.1.0.jar的org.apache.spark.deploy.master下的Master类 //截取了部分代码 //处理 ...
 - Spring4学习回顾之路08- FactoryBean配置Bean
			
建立Student.java package com.lql.srping04; /** * @author: lql * @date: 2019.10.28 * Description: */ pu ...
 - layui 实现图片上传和预览
			
[学习笔记] 图片不自动上传并在表单提交时再上传,看代码. 附上表单页面 前台实现 <#--图片名--><input id="fileName" type=&qu ...
 - FZU2275 Game(kmp
			
暑假wa的题了,,,看见vj的attempt痕迹打算挨个补了,简单kmp题,判断bob的串是不是全为0或者是alice的字串就好了 #include<algorithm> #include ...
 - Linux就该这么学——新手必须掌握的命令之文件编辑命令组
			
cat 命令 用途 : 用于查看纯文本文件 格式 : cat [选项] [文件] 示例 : more 命令 用途 : 用于查看纯文本文件(内容较多的),可以用”Enter” 键或者”Space”键向下 ...
 - (0)c++入门——认识指针与数组——指针即是内存中地址。
			
初识指针 首先需要了解一个概念,计算机的内存(或者说是寄存器)都是有地址的. <c++ primer plus>一书P37中提到这样一个概念:为把信息存储在计算机中,程序必须记录3个基本属 ...