CodeForces 660D Number of Parallelograms
2016-05-01 17:58
363 查看
#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<memory.h> #include<functional> #include<limits.h> #include<vector> #include<algorithm> #include<cmath> #include<iomanip> #include<set> #include<map> using namespace std; const int maxn = 2005; struct point { int x, y; point(int x1 = 0, int y1 = 0) :x(x1), y(y1) {} }p[maxn]; struct vec { int x, y; vec(int x1, int y1) :x(x1), y(y1) {} bool operator==(const vec& v) const { return x == v.x && y == v.y; } bool operator<(const vec& v) const { if (x == v.x) return y < v.y; return x < v.x; } }; int main() { int n; while (cin >> n) { for (int i = 0; i < n; ++i) { cin >> p[i].x >> p[i].y; } map<vec, int> mp; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { int x = p[i].x - p[j].x; int y = p[i].y - p[j].y; if (x < 0) x = -x, y = -y; if (x == 0 && y < 0) y = -y; vec temp1(x, y); mp[temp1]++; } } bool ok = false; long long cnt = 1; map<vec, int>::iterator it; for (it = mp.begin(); it != mp.end(); ++it) { if (it->second >= 2) { ok = true; cnt += it->second * (it->second-1) / 2; } } if (ok) cout << cnt/2 << endl; else cout << 0 << endl; } return 0; }
暴力枚举,找到一组相等的向量→肯定可以构成一个平行四边形(肯定还会出现它的另一对边,这里相当于多算了一次,故最后结果除以2)
相关文章推荐
- linux的ulimit各种限制之深入分析
- poj 2234
- 线程同步和线程死锁
- RPC和RMI的区别(Difference Between RPC and RMI)
- 计算n的阶乘
- Swift基础01
- MongoDB基础
- 延云YDB&&YA100安装部署文档
- 延云YDB&&YA100安装部署文档
- 延云YDB&&YA100安装部署文档
- 延云YDB&&YA100安装部署文档
- 延云YDB&&YA100安装部署文档
- 延云YDB&&YA100安装部署文档
- 延云YDB&&YA100安装部署文档
- 延云YDB&&YA100安装部署文档
- 延云YDB&&YA100安装部署文档
- 延云YDB&&YA100安装部署文档
- 延云YDB&&YA100安装部署文档
- 延云YDB&&YA100安装部署文档
- 延云YDB&&YA100安装部署文档