链接:

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. 删除List集合中的元素你碰到过这样的陷阱吗?

    删除List的三种方式: (1) 普通遍历 : @Test public void testList(){ ArrayList<String> list = new ArrayList&l ...

  2. int main(int argc, char *argv[])解释

    int main(int argc, char *argv[]) 详解: #include <stdio.h> int main(int argc, char *argv[]) { int ...

  3. TextField 、 FTE、 TLF 的使用情景和简单说明

    作者:tiangej 来源:CSDN 原文:https://blog.csdn.net/tiangej/article/details/16859239 版权声明:本文为博主原创文章,转载请附上博文链 ...

  4. windows10环境下的RabbitMQ安装_笔记

    原文:https://blog.csdn.net/weixin_39735923/article/details/79288578 第一步:下载并安装erlang原因:RabbitMQ服务端代码是使用 ...

  5. python中的可哈希与不可哈希

    什么是可哈希(hashable)? 简要的说可哈希的数据类型,即不可变的数据结构(字符串str.元组tuple.对象集objects). 哈希有啥作用? 它是一个将大体量数据转化为很小数据的过程,甚至 ...

  6. golang ---获取磁盘信息

    package main import ( "fmt" "github.com/StackExchange/wmi" ) type Storage struct ...

  7. Flutter 与 Android 的交互

    https://juejin.im/post/5cd91de4518825686b120921 https://juejin.im/entry/5b64292be51d451995676398

  8. sql强大的行转列功能(内置函数pivot及注意事项)

    语法: PIVOT用于将列值旋转为列名(即行转列),在SQL Server 2000可以用聚合函数配合CASE语句实现 PIVOT的一般语法是:PIVOT(聚合函数(列) FOR 列 in (…) ) ...

  9. orangepi自启动打开一个终端并且运行脚本

    第一步: 在 /home/pi/.config 下创建一个文件夹,名称为 autostart,如果已经存在则不需要创建 第二步: 在autostart文件夹中创建桌面启动项文件,(文件名以 .desk ...

  10. git stash 缓存本地修改 简介

    当我们在使用git的时候,又是会有这种情况:当新的需求了的时候.我们需要为此需求新建一个分支,再次分支上进行修改,当经过测试,提交代码时,在将其合并到主分支,或生产分支上. 但是有时候也有失误的时候, ...