Parallelogram Counting(平行四边形个数,思维转化)
| Time Limit: 2 second(s) | Memory Limit: 32 MB |
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 integersx 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 |
Output for 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 |
Case 1: 5 Case 2: 6 |
题解:
给一系列点,让找到可以组成的平行四边形的个数;
思路:由于平行四边形的交点是唯一的,那么我们只要记录每两个直线的交点,判断交点重复的个数可以求出来了;假设有这个交点有三个重复的,则ans+=3*2/2;
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
typedef long long LL;
const int MAXN=;
struct Dot{
double x,y;
bool operator < (const Dot &b) const{
if(x!=b.x)return x<b.x;
else return y<b.y;
}
};
Dot dt[MAXN];
Dot num[MAXN*MAXN];
int main(){
int T,N,kase=;
scanf("%d",&T);
while(T--){
scanf("%d",&N);
for(int i=;i<N;i++)scanf("%lf%lf",&dt[i].x,&dt[i].y);
int tp=;
for(int i=;i<N;i++)
for(int j=i+;j<N;j++){
if(dt[i].x==dt[j].x&&dt[i].y==dt[j].y)continue;
num[tp].y=(dt[i].y+dt[j].y)/;
num[tp].x=(dt[i].x+dt[j].x)/;
tp++;
}
sort(num,num+tp);
LL ans=,cur=;
for(int i=;i<tp;i++){
if(num[i].x==num[i-].x&&num[i].y==num[i-].y)cur++;
else{
ans+=cur*(cur-)/;cur=;
}
}
printf("Case %d: %lld\n",++kase,ans);
}
return ;
}
Parallelogram Counting(平行四边形个数,思维转化)的更多相关文章
- 计算几何 + 统计 --- Parallelogram Counting
Parallelogram Counting Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5749 Accepted: ...
- 1058 - Parallelogram Counting 计算几何
1058 - Parallelogram Counting There are n distinct points in the plane, given by their integer coord ...
- POJ 1971 Parallelogram Counting (Hash)
Parallelogram Counting Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 6895 Acc ...
- LightOJ 1058 - Parallelogram Counting 几何思维
http://www.lightoj.com/volume_showproblem.php?problem=1058 题意:给你顶点,问能够成多少个平行四边形. 思路:开始想使用长度来扫描有多少根,但 ...
- Light OJ - 1058 Parallelogram Counting(判定平行四边形)
Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...
- POJ 1791 Parallelogram Counting(求平行四边形数量)
Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...
- 简单题思维转化BestCoder
题意:给你a, b, c, d四个数,这几个数的范围都是大于0小于1000的整数,让比较 a ^b 和 c ^ d的大小. 这道题看着特别简单,但是当时就是做不出来,将近一个月没有做题了,手生了,不过 ...
- Codeforces 911D. Inversion Counting (数学、思维)
题目链接:Inversion Counting 题意: 定义数列{ai|i=1,2,...,n}的逆序对如下:对于所有的1≤j<i≤n,若ai<aj,则<i,j>为一个逆序对. ...
- Number of Parallelograms(求平行四边形个数)
Number of Parallelograms time limit per test 4 seconds memory limit per test 256 megabytes input sta ...
随机推荐
- 百度地图V1.5 LocalSearch增加浮动窗体的操作内容
1.初始化LocalSearch控件 LocalSearch = new BMap.LocalSearch(map, { renderOptions : { map : map, panel : & ...
- 关于uitableView的Group模式滑动偏移问题
问题: uitableView的group模式自带一个section的headerView,如果不调整,系统就会默认高度,在滑动时就会向下偏移一个单位的scetion高度,我们改变tableView的 ...
- #292 (div.2) D.Drazil and Tiles (贪心+bfs)
Description Drazil created a following problem about putting × tiles into an n × m grid: "The ...
- MD5加密算法(转)
获取字符串的MD5摘要 原文更详细: http://www.weixuehao.com/archives/474 代码如下: import java.security.MessageDigest; p ...
- 对数组元素进行排序的方法总结(利用C++)
首先,对数组元素进行排序方法总结为以下两类: 一.简单排序算法(时间复杂度O(n*n)) 1.插入排序 2.选择排序 3.交换排序,即冒泡排序 二.先进排序算法(时间复杂度O(n*logn)) 1.快 ...
- Selenium模块化
概述 高内聚低耦合是软件设计的一个基本原则. 内聚:从功能角度来度量模块内的联系,一个好的内聚模块应当恰好做一件事.它描述的是模块内的功能联系. 耦合:各模块之间相互连接的一种度量,耦合强弱取决于模块 ...
- 开源 java CMS - FreeCMS1.9公布。
FreeCMS商业版V1.9更新功能 添加Oracle数据库支持.
- Redux中的重要概念
Action/Reducer/Store 首先,先看看第一张图,图中展示了Redux的单向数据流,以及Action.Reducer和Store这三个核心概念. 下面就围绕上图,非别介绍Action.R ...
- UGUI实现的虚拟摇杆,可改变摇杆位置
实现方式主要参考这篇文章:http://www.cnblogs.com/plateFace/p/4687896.html. 主要代码如下: using UnityEngine; using Syste ...
- android 补间动画
android开发过程中,为了更好的展示应用程序,应用程序添加动画,能够很好地实现这个功能.如果动画中的图像变化有一定的规律,可以采用自动生成图像的方式来生成动画,例如图像的移动.旋转.缩放等.自动生 ...