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>为一个逆序对. ...
随机推荐
- PAT(B) 1065 单身狗(Java:17分,C:25分)
题目链接:1065 单身狗 (25 point(s)) 题目描述 "单身狗"是中文对于单身人士的一种爱称.本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱. 输入格式 ...
- AttributeError: 'sys.flags' object has no attribute 'utf8_mode'
AttributeError: 'sys.flags' object has no attribute 'utf8_mode' pycharm工程的py版本是3.6,结果即使使用py3.7编译后的py ...
- MySQL练手小试题
创建表和数据 创建class表 create table class ( cid int(11) primary key auto_increment, caption varchar(32) not ...
- @FeignClient 情况下header的传递方法,RestTemplate情况下Header传递方法
今天因为要调用另一个服务,因为我们用的是SpringCloud框架,所以通过Fegin调用,正好另一方服务有权限校验,需要传递token和设备ID,这两个参数都需要放到Header中, 用 @Requ ...
- IDEA远程DEBUG Tomcat配置
IDEA远程DEBUG Tomcat配置 IDEA远程DEBUG Tomcat很简单,配置如下: 1.修改tomcat服务器配置 打开tomcat/bin/catalina.sh 在空白处添加如下参数 ...
- 可拖拽dialog
指令的封装转自https://blog.csdn.net/sinat_21902709/article/details/86545444 可拖拽dialog应用于很多弹出框,所以需要作用于全局 在插件 ...
- 能够提高PHP的性能的一些注意事项
1. 如果能将类的方法定义成static,就尽量定义成static,它的速度会提升将近4倍.(静态类调用属性和方法,只可以调用静态属性和方法.self::方法名().self::属性名.只有实例化 ...
- ASPxClientGridView(客户端选择某一行的值的调用)
- 安恒pwn魔法
魔法这是比较基础的一道栈溢出: 首先看下开启的防护机制 Checksec magicc发现只有nx防护 我们载入ida发现溢出点 Buf实际溢出空间为0x16,构造exp import time fr ...
- mtd设备操作、jffs2
安装mtd相关命令 手动安装mtd-utils,根据系统自行选择 mtd交叉编译:https://blog.csdn.net/zhangxuechao_/article/details/5212442 ...