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 ...
随机推荐
- Gas Station 解答
Problem There are N gas stations along a circular route, where the amount of gas at station i is gas ...
- C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating\11.0
Generating Files with the TextTransform Utility \Program Files\Common Files\Microsoft Shared\TextTem ...
- Cocos2d-x 架构一个游戏的一般思路
采用下面的步骤来实现游戏逻辑: 通过应用程序代理类来初始化第一个CCScene(即AppDelegate里面的第一个CCScene), CCScene里面实例化一个或者多个CCLayer,并把它们当作 ...
- PHP MySQL Delete From 之 Delete
删除数据库中的数据 DELETE FROM 语句用于从数据库表中删除记录. 语法 DELETE FROM table_name WHERE column_name = some_value 注释:SQ ...
- More is better(并差集)
More is better Time Limit : 5000/1000ms (Java/Other) Memory Limit : 327680/102400K (Java/Other) To ...
- Nginx学习之四-Nginx进程同步方式-自旋锁(spinlock)
自旋锁简介 Nginx框架使用了三种消息传递方式:共享内存.套接字.信号. Nginx主要使用了三种同步方式:原子操作.信号量.文件锁. 基于原子操作,nginx实现了一个自旋锁.自旋锁是一种非睡眠锁 ...
- Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException
异常Log: Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessE ...
- 物理机与虚拟机IP互ping通,而互ping主机名不通
问题描述:虚拟机信息:VMware-workstation 10安装RHEL5.8操作系统.hostname:rhel201.com IP:192.168.1.201 物理机系统:windows 7主 ...
- nat网络穿透整理笔记(思维导图)
mindmanger整理的,关于Nat穿透,图片太小,可以点击放大,单独看图片.
- ECSHOP首页站内快讯在哪里添加和修改?
“添加新闻后在首页站内快讯处显示不出来?”.“请问首页中站内快讯(最新文章)在后台哪个位置管理”.“如何让发布的文章进入首页站内快讯”等等诸如此类的问题,经常在论坛里看到一些朋友在询问. 本ECSHO ...