Educational Codeforces Round 11-D. Number of Parallelograms

本文介绍了一种通过计算向量来检测平面中是否存在平行四边形的算法。该算法利用了平行四边形的性质——对边平行且相等,并使用C++实现了一个具体的例子。通过将点坐标转换为向量并统计相似向量的数量,可以有效地找出平行四边形。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用两条边平行且相等,判断平行四边形。
把所有边转换成向量。mulitest 记录每种向量的个数,在统计

#include <bits/stdc++.h>
#define maxn 100005
#define INF 1e9
using namespace std;
typedef long long ll;

struct Node{
    Node(){
    }
    Node(int a, int b){
        x = a;
        y = b;
    }
    int x, y;
    ll len;
    friend bool operator < (const Node &p1, const Node &p2){
        if(p1.x == p2.x && p1.y == p2.y)
          return p1.len < p2.len;
        if(p1.x == p2.x)
          return p1.y < p2.y;
        return p1.x < p2.x;
    }
};
int x[2005], y[2005];
multiset<Node> m;
int main(){

   // freopen("in.txt", "r", stdin);
    int n;

    while(cin >> n){

        m.clear();
        for(int i = 0; i < n; i++){
            scanf("%d%d", x+i, y+i);
        }
        ll cnt = 0;

        for(int i = 1; i < n; i++){
          for(int j = 0; j < i; j++){
            int h1 = x[i] - x[j], h2 = y[i] - y[j];
            Node p;
            if(h1 == 0){
             p = Node(h1, abs(h2));
            }
            else{
              ll d = h1 * h2;
              p = Node(abs(h1), d / abs(h1));
             }
            p.len = ((ll)h1 * h1 + (ll)h2 * h2);
            cnt += m.count(p);
            m.insert(p);
          }
        }
       cout << cnt / 2 << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值