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>为一个逆序对. ...
随机推荐
- [转帖]Linux教程(21)-Linux条件循环语句
Linux教程(21)-Linux条件循环语句 2018-08-24 16:49:03 钱婷婷 阅读数 60更多 分类专栏: Linux教程与操作 Linux教程与使用 版权声明:本文为博主原创文 ...
- [转帖]微软宣布加入 OpenJDK 项目
微软宣布加入 OpenJDK 项目 https://news.cnblogs.com/n/646003/ 近日,微软的 Bruno Borges 在 OpenJDK 邮件列表中发布了一条消息,内容包含 ...
- Django——用户认证
Django--用户认证 用户与Authentication(身份验证) Django 用户认证系统处理用户帐号,组,权限以及基于cookie的用户会话. 这个系统一般被称为 auth/auth (认 ...
- Python-22-并发编程
一.进程 1. 什么是进程 狭义定义:进程是正在运行的程序的实例(an instance of a computer program that is being executed).广义定义:进程是一 ...
- 跨域和CORS
一 跨域 同源策略(Same origin policy)是一种约定,它是浏览器最核心也最基本的安全功能,如果缺少了同源策略,则浏览器的正常功能可能都会受到影响.可以说Web是构建在同源策略基础之上的 ...
- 用Python递归做个多层次的文件执行
想用 递归实现多层次的 '.py'执行但是发现好像不能 import os def func(path): if os.path.isdir(path): for name in os.listdir ...
- ASP.NET MVC请求参数字符串之区分空与NULL
开发中经常会写增删改查的功能,这里记录下在更新操作时遇到的一个问题. 假设一个模型对应数据库中某一张表,在更新时便需要区分是一次性更新全部字段还是仅更新部分字段.希望能做到传递某个参数时便更新,未传递 ...
- MySQL数据库-表操作-SQL语句(二)
1. MySQL多表查询 1.1 外键约束 为了消除多张表查询出现的笛卡尔积的现象,MySQL在建表并进行多表之间的关键查询可以使用外键关联查询. 外键:从表1(sub)的某列引用(ref)另外一个表 ...
- Oracle数据库连接超时
关于Oracle数据库的连接失败问题,有N种情况都会导致,这次遇到的是一般开发或者运维人员难以发现的 场景: 有一台机A能够正常连接数据库并正常运行,机器B连接失败 32位WebService程序基于 ...
- power shell命令添加SharePoint用户组与用户(用户为域用户)
查看SharePoint用户组 Get-PnPGroup 查看某一用户组 Get-PnPGroup -Identity "用户组名" 查看某一用户组下的所有成员 Get-PnPGr ...