首页 > 代码库 > 百练2805:正方形
百练2805:正方形
传送门:http://bailian.openjudge.cn/practice/2805/
【题解】
n不大,枚举两个端点,推算出剩下两个,拿map或哈希看看有多少即可。
# include <map> # include <stdio.h> # include <string.h> # include <iostream> # include <algorithm> // # include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; const int M = 5e5 + 10; const int mod = 1e9+7; # define RG register # define ST static int n; struct point { int x, y; point() {} point(int x, int y) : x(x), y(y) {} friend bool operator == (point a, point b) { return a.x == b.x && a.y == b.y; } friend bool operator != (point a, point b) { return !(a==b); } friend bool operator < (point a, point b) { return a.x < b.x || (a.x == b.x && a.y < b.y); } friend bool operator > (point a, point b) { return a.x > b.x || (a.x == b.x && a.y > b.y); } }p[M]; map < point, int > mp; inline void getpoint(point a, point b, point &c, point &d) { // a->b, right a->d int dy = b.y - a.y, dx = a.x - b.x; d = point(a.x + dy, a.y + dx); c = point(b.x + dy, b.y + dx); } int main() { while(cin >> n) { if(!n) break; ll ans = 0; mp.clear(); for (int i=1; i<=n; ++i) { scanf("%d%d", &p[i].x, &p[i].y); mp[p[i]] = mp[p[i]] + 1; } for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j) { if(i == j || p[i] == p[j]) continue; point a, b; getpoint(p[i], p[j], a, b); if(a != p[i] && a != p[j] && b != p[i] && b != p[j]) { if(mp.find(a) != mp.end() && mp.find(b) != mp.end()) { ans += 1ll * mp[a] * mp[b]; // printf("(%d,%d), (%d,%d), (%d,%d), (%d,%d)\n", p[i].x, p[i].y, p[j].x, p[j].y, a.x, a.y, b.x, b.y); // printf("%d == %d\n", mp[a], mp[b]); } } } cout << ans/4 << endl; } return 0; }
百练2805:正方形
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。