链接:

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\n", res);
} return 0;
}

LightOJ - 1058 - Parallelogram Counting(数学,计算几何)的更多相关文章

  1. LightOJ 1058 - Parallelogram Counting 几何思维

    http://www.lightoj.com/volume_showproblem.php?problem=1058 题意:给你顶点,问能够成多少个平行四边形. 思路:开始想使用长度来扫描有多少根,但 ...

  2. 1058 - Parallelogram Counting 计算几何

    1058 - Parallelogram Counting There are n distinct points in the plane, given by their integer coord ...

  3. Light OJ - 1058 Parallelogram Counting(判定平行四边形)

    Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...

  4. Parallelogram Counting(平行四边形个数,思维转化)

    1058 - Parallelogram Counting    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit ...

  5. lightoj 1148 Mad Counting(数学水题)

    lightoj 1148 Mad Counting 链接:http://lightoj.com/volume_showproblem.php?problem=1148 题意:民意调查,每一名公民都有盟 ...

  6. 计算几何 + 统计 --- Parallelogram Counting

    Parallelogram Counting Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5749   Accepted: ...

  7. POJ 1971 Parallelogram Counting (Hash)

          Parallelogram Counting Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 6895   Acc ...

  8. LightOJ 1062 - Crossed Ladders 基础计算几何

    http://www.lightoj.com/volume_showproblem.php?problem=1062 题意:问两条平行边间的距离,给出从同一水平面出发的两条相交线段长,及它们交点到水平 ...

  9. Codeforces 911D. Inversion Counting (数学、思维)

    题目链接:Inversion Counting 题意: 定义数列{ai|i=1,2,...,n}的逆序对如下:对于所有的1≤j<i≤n,若ai<aj,则<i,j>为一个逆序对. ...

随机推荐

  1. Python爬虫b站视频弹幕并生成词云图分析

    爬虫:requests,beautifulsoup 词云:wordcloud,jieba 代码加注释: # -*- coding: utf-8 -*- import xlrd#读取excel impo ...

  2. Different Subsets For All Tuples CodeForces - 660E (组合计数)

    大意: 定义$f(a)$表示序列$a$本质不同子序列个数. 给定$n,m$, 求所有长$n$元素范围$[1,m]$的序列的$f$值之和. 显然长度相同的子序列贡献是相同的. 不考虑空串, 假设长$x$ ...

  3. Redis之RDB和AOF持久化介绍

    什么是数据库状态 redis是一个键值对的数据库服务器,服务器中通常包含中任意个非空的数据库,而每个数据库又可以包含任意个键值对,为了方便起见,我们将服务器中的非空数据库以及他们的键值对统称为数据库状 ...

  4. 未检测到.NET CORE SDK 或者 新建项目没有.NET CORE 3.0选择项

    终于解决了 首先先看自己的VS2019版本 由于楼主下载的 .NET CORE SDK 3.0.100-preview8-013656 焕然大悟 原来是版本不符合,需要用vs 2019 preview ...

  5. Jenkins的语法之pipeline

    如果不处理,pipeline:stages中任一stage失败,都会致使其以下stage都失败,那么处理方式为: 1.stage在可能出错的地方添加try catch语句 如:try{} catch( ...

  6. python 简单工厂模式

    abc 是抽象类模块abc.ABC 是继承抽象类  也可直接继承 (metaclass=ABCMeta)abc.abstractmethod 是定义抽象方法 简单工厂模式:通过接口创建对象,但不会暴露 ...

  7. Linux 基础学习2

    目录 Linux 基础学习2 文件目录结构 文件命名规范 文件系统结构 linux应用程序的组成 绝对路径和相对路径 目录名和基名 切换目录 切换到家目录 切换到上一次的目录 显示当前的工作目录 列出 ...

  8. Ane技术大全 - Devil程序员

    来源:http://www.th7.cn/Program/Android/201405/206863.shtml 一.Ane概况 1.Ane是什么? Ane是为了解决 as3(flash)与Java代 ...

  9. Android多种方式实现相机圆形预览

    效果图如下: 一.为预览控件设置圆角 为控件设置ViewOutlineProvider public RoundTextureView(Context context, AttributeSet at ...

  10. win10开启redis失败解决方案

    输入命令:redis-server redis.windows.conf 提示:解决redis无法启动,报错:无法将“redis-server”项识别为 cmdlet.函数.脚本文件或可运行程 序的名 ...