POJ 1791 Parallelogram Counting(求平行四边形数量)
Description
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.
Input
Input starts with an integer T (≤ 15), denoting the number of test cases.
The first line of each test case contains an integer n (1 ≤ n ≤ 1000). Each of the next n lines, contains 2 space-separated integers x and y (the coordinates of a point) with magnitude (absolute value) of no more than 1000000000.
Output
For each case, print the case number and the number of parallelograms that can be formed.
Sample Input
2
6
0 0
2 0
4 0
1 1
3 1
5 1
7
-2 -1
8 9
5 7
1 1
4 8
2 0
9 8
Sample Output
Case 1: 5
Case 2: 6
给出点的坐标求出能连成平行四边形的数量。
思路:
用结构体记录每两个点的x坐标和与y坐标和( 相当于记录这两个点为对角线的情况 )然后循环判断多少个对角线的被交点平分(结构体中x,y的值相等)求出对角线的数量,然后C(sum,2)。
#include<cstdio>
#include<algorithm>
using namespace std;
int x[],y[];
struct stu
{
int x,y;
}st[*/];
bool cmp(stu a,stu b)
{
if(a.x != b.x)
return a.x < b.x;
else
return a.y < b.y;
}
int main()
{
int t,ss=;
scanf("%d",&t);
while(t--)
{
int n,i,j;
scanf("%d",&n);
for(i = ; i < n ; i++)
{
scanf("%d %d",&x[i],&y[i]);
}
int k=;
for(i = ; i < n ; i++)
{
for(j = i+ ; j < n ; j++)
{
st[k].x=x[i]+x[j];
st[k++].y=y[i]+y[j];
}
}
sort(st,st+k,cmp);
int num=,sum=,ans=;
for(i = ; i < k ; i++)
{
if(st[num].x == st[i].x && st[num].y == st[i].y)
sum++; //sum代表线的数量
else
{
ans+=(sum*(sum-)/); //这里是C(sum,2)
num=i;
sum=; }
}
printf("Case %d: %d\n",++ss,ans);
}
}
POJ 1791 Parallelogram Counting(求平行四边形数量)的更多相关文章
- Parallelogram Counting(平行四边形个数,思维转化)
1058 - Parallelogram Counting PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit ...
- POJ 1971 Parallelogram Counting (Hash)
Parallelogram Counting Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 6895 Acc ...
- poj 1144 (Tarjan求割点数量)
题目链接:http://poj.org/problem?id=1144 描述 一个电话线公司(简称TLC)正在建立一个新的电话线缆网络.他们连接了若干个地点分别从1到N编号.没有两个地点有相同的号码. ...
- POJ 1971 Parallelogram Counting
题目链接: http://poj.org/problem?id=1971 题意: 二维空间给n个任意三点不共线的坐标,问这些点能够组成多少个不同的平行四边形. 题解: 使用的平行四边形的判断条件:对角 ...
- 计算几何 + 统计 --- Parallelogram Counting
Parallelogram Counting Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5749 Accepted: ...
- POJ1144 Network 题解 点双连通分量(求割点数量)
题目链接:http://poj.org/problem?id=1144 题目大意:给以一个无向图,求割点数量. 这道题目的输入和我们一般见到的不太一样. 它首先输入 \(N\)(\(\lt 100\) ...
- 1058 - Parallelogram Counting 计算几何
1058 - Parallelogram Counting There are n distinct points in the plane, given by their integer coord ...
- poj 1474 Video Surveillance - 求多边形有没有核
/* poj 1474 Video Surveillance - 求多边形有没有核 */ #include <stdio.h> #include<math.h> const d ...
- 洛谷 P1451 求细胞数量
题目链接 https://www.luogu.org/problemnew/show/P1451 题目描述 一矩形阵列由数字0到9组成,数字1到9代表细胞,细胞的定义为沿细胞数字上下左右若还是细胞数字 ...
随机推荐
- BI的意义
BI系统建设的价值,有可能不值钱,也有可能价值数千万,就看我们大家好用了没.”所以,BI系统建设的收获,终究还是因企业而异的,再归根,便是与企业的文化,与企业的人,尤其是管理层是极为相关的了. 商业智 ...
- 图像分类丨Inception家族进化史「GoogleNet、Inception、Xception」
引言 Google提出的Inception系列是分类任务中的代表性工作,不同于VGG简单地堆叠卷积层,Inception重视网络的拓扑结构.本文关注Inception系列方法的演变,并加入了Xcept ...
- 4. 把一幅彩色图像的R、G、B分量单独显示。
#include <cv.h> #include <highgui.h> int main(void) { IplImage* oo = cvLoadImage(); IplI ...
- Unity注入
[此文引用别人,作为随笔自己看.]今天写<WCF技术剖析(卷2)>关于<WCF扩展>一章,举了“如何通过WCF扩展实现与IoC框架(以Unity为例)集成”(<通过自定义 ...
- 时间日期相关:Date类、DateFormat类、Calendar类
1 Date类 类 Date 表示特定的瞬间,精确到毫秒. 1秒=1000毫秒 毫秒的0点:公元1970年 一月一日,午夜0:00:00 对应的毫秒值就是0 时间和日期的计算,必须依赖毫秒值. Sys ...
- 织梦后台上传mp4视频不显示
include/dialog/select_media.php ,约185行, 把(rm|rmvb) 改为(rm|mp4|rmvb)
- springboot 2.0 Redis command timed out的解决
环境:springboot 2.0.7 spring data redis springboot从1.x升级到2.x后,spring data redis使用的redis客户端驱动从1.x的jedis ...
- for循环/计算坐标
for循环计算坐标 webqq里面有类似桌面的各种图标,是绝对定位的,这样可以拖动改变位置,用浮动的话,没法拖动. <!DOCTYPE html> <html lang=" ...
- Jenkins系列——使用Dashboard View分类展示作业
1.目标 创建的作业多了,在一个视图中展示多有不便.因此需要使用 Dashboard View 将作业按照后缀进行分类展示. 如下图,可以按照后缀添加CODE,TEST和OTHER视图. 2.环境说明 ...
- tsung基准测试方法、理解tsung.xml配置文件、tsung统计报告简介
网上搜集的资料,资料来源于:http://blog.sina.com.cn/ishouke 1.tsung基准测试方法 https://pan.baidu.com/s/1Ne3FYo8XyelnJy8 ...