LightOJ - 1058 - Parallelogram Counting(数学,计算几何)
链接:
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(数学,计算几何)的更多相关文章
- LightOJ 1058 - Parallelogram Counting 几何思维
http://www.lightoj.com/volume_showproblem.php?problem=1058 题意:给你顶点,问能够成多少个平行四边形. 思路:开始想使用长度来扫描有多少根,但 ...
- 1058 - Parallelogram Counting 计算几何
1058 - Parallelogram Counting There are n distinct points in the plane, given by their integer coord ...
- Light OJ - 1058 Parallelogram Counting(判定平行四边形)
Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...
- Parallelogram Counting(平行四边形个数,思维转化)
1058 - Parallelogram Counting PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit ...
- lightoj 1148 Mad Counting(数学水题)
lightoj 1148 Mad Counting 链接:http://lightoj.com/volume_showproblem.php?problem=1148 题意:民意调查,每一名公民都有盟 ...
- 计算几何 + 统计 --- Parallelogram Counting
Parallelogram Counting Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5749 Accepted: ...
- POJ 1971 Parallelogram Counting (Hash)
Parallelogram Counting Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 6895 Acc ...
- LightOJ 1062 - Crossed Ladders 基础计算几何
http://www.lightoj.com/volume_showproblem.php?problem=1062 题意:问两条平行边间的距离,给出从同一水平面出发的两条相交线段长,及它们交点到水平 ...
- Codeforces 911D. Inversion Counting (数学、思维)
题目链接:Inversion Counting 题意: 定义数列{ai|i=1,2,...,n}的逆序对如下:对于所有的1≤j<i≤n,若ai<aj,则<i,j>为一个逆序对. ...
随机推荐
- 3.JVM 垃圾收集器
Garbage Collect(垃圾回收) 1.1 如何确定一个对象是垃圾? 要想进行垃圾回收,得先知道什么样的对象是垃圾. 1.1.1 引用计数法 对于某个对象而言,只要应用程序中持有该对象的引用, ...
- 92. 反转链表 II
反转从位置 m 到 n 的链表.请使用一趟扫描完成反转. 说明: 1 ≤ m ≤ n ≤ 链表长度. 示例: 输入: 1->2->3->4->5->NULL, m ...
- python with方法
在实际的编码过程中,有时有一些任务,需要事先做一些设置,事后做一些清理,这时就需要python with出场了,with能够对这样的需求进行一个比较优雅的处理,最常用的例子就是对访问文件的处理. 一般 ...
- Oracle 11g 总结篇2
第一部分: 字段名的别名用""括起来,如:last_name as "姓名". 去除重复:在投影的字段名前加上 distinct 就可以了. 比如:select ...
- ColorTransform调整显示对象的颜色值
ColorTransform调整显示对象的颜色值: /** * * *------------------------------* * | *** 调整显示对象的颜色值 *** | * *----- ...
- c# NPOI文件操作
public static Byte[] RenderDataToExcel<T>(List<T> SourceList, List<String> filter) ...
- [高清·非影印] Docker 容器与容器云(第2版)
------ 郑重声明 --------- 资源来自网络,纯粹共享交流, 如果喜欢,请您务必支持正版!! --------------------------------------------- 下 ...
- Bootstrap-table 使用总结,和其参数说明
转载于:https://www.cnblogs.com/laowangc/p/8875526.html 一.什么是Bootstrap-table? 在业务系统开发中,对表格记录的查询.分页.排序等处理 ...
- Thomas Brinkhoff 基于路网的移动对象生成器的使用[第二版]
Thomas Brinkhoff 基于路网的移动对象生成器的使用 Thomas Brinkhoff 基于路网的移动对象生成器的使用 相关操作的说明 相关文件的说明 运行 导入eclipse后运行时选择 ...
- Mycat分布式数据库架构解决方案--Server.xml详解
echo编辑整理,欢迎转载,转载请声明文章来源.欢迎添加echo微信(微信号:t2421499075)交流学习. 百战不败,依不自称常胜,百败不颓,依能奋力前行.--这才是真正的堪称强大!!! 该文件 ...