Codeforces 660D Number of Parallelograms 【思维】
来源:互联网 发布:索引超出数据界限 编辑:程序博客网 时间:2024/05/29 17:06
题目链接:Codeforces 660D Number of Parallelograms
D. Number of Parallelograms
time limit per test4 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points.
Input
The first line of the input contains integer n (1 ≤ n ≤ 2000) — the number of points.
Each of the next n lines contains two integers (xi, yi) (0 ≤ xi, yi ≤ 109) — the coordinates of the i-th point.
Output
Print the only integer c — the number of parallelograms with the vertices at the given points.
Example
input
4
0 1
1 0
1 1
2 0
output
1
题意:n个点,问你最多可以构成的平行四边形。
老题啦,平行四边形对角线中点重合,所以找中点就好了。
AC代码:
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <vector>#include <map>#define ll o<<1#define rr o<<1|1#define CLR(a, b) memset(a, (b), sizeof(a))using namespace std;typedef long long LL;typedef pair<double, double> pii;const int INF = 0x3f3f3f3f;const int MAXN = 3*1e5 + 10;double x[2010], y[2010];pii ans[2001*2001];map<pii, int> fp;int main(){ int n; while(scanf("%d", &n) != EOF) { for(int i = 1; i <= n; i++) { scanf("%lf%lf", &x[i], &y[i]); } fp.clear(); int top = 0; for(int i = 1; i <= n; i++) { for(int j = i+1; j <= n; j++) { double xx = (x[i] + x[j]) / 2; double yy = (y[i] + y[j]) / 2; fp[pii(xx, yy)]++; ans[top++] = pii(xx, yy); } } sort(ans, ans+top); int N = unique(ans, ans+top) - ans; LL res = 0; for(int i = 0; i < N; i++) { int v = fp[ans[i]]; res += 1LL * v * (v-1) / 2; } printf("%lld\n", res); } return 0;}
- Codeforces 660D Number of Parallelograms 【思维】
- Number of Parallelograms CodeForces 660D 思维题
- codeforces 660D. Number of Parallelograms
- CodeForces 660D Number of Parallelograms
- Codeforces 660D Number of Parallelograms
- CodeForces 660D Number of Parallelograms
- CodeForces 660D Number of Parallelograms
- CodeForces 660D. Number of Parallelograms【模拟】
- codeforces 660D - Number of Parallelograms
- CodeForces 660D Number of Parallelograms
- CodeForces 660D Number of Parallelograms(水题)
- Codeforces 660D Number of Parallelograms【平行四边形个数】
- CodeForces 660D Number of Parallelograms [想法题]
- D. Number of Parallelograms
- D. Number of Parallelograms
- D. Number of Parallelograms
- Number of Parallelograms CodeForces
- Educational Codeforces Round 11-D. Number of Parallelograms
- 1268 和为K的组合
- Android版股票K线图实现方案
- Jsp自定义标签
- hdu1425 sort(哈希表)
- HDU 5394 Trie in Tina Town
- Codeforces 660D Number of Parallelograms 【思维】
- hdu 1698 Just a Hook lazy线段树
- ubuntu软件源-sources.list
- nrf51822开发指导之静态密钥配对--在SDK9.0的ble_app_uart例程修改
- 数据库去重
- Git入门(一)简易的命令行入门教程:
- ubuntu15.10 3D桌面
- 深入了解Handler消息机制(一)
- 手势监测器的使用