二分查找一个点是否存在,用set无法避免素数陷阱,无法解决负数取模问题,用map也无法解决。
只能hash或者二分
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <stack>
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define l(x) ((x)<<1)
#define r(x) ((x)<<1|1)
#define lowbit(x) ((x)&(-(x)))
#define abs(x) ((x)>=0?(x):(-(x)))
#define ms(a,b) memset(a,b,sizeof(a))
#define NSYNC std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
using namespace std;
struct node {
int x, y;
bool operator < (const node &p) const {
if (x == p.x) return y < p.y;
return x < p.x;
}
bool operator == (const node &p) const {
return x == p.x && y == p.y;
}
};
node demo[1111];
bool check(const node &target, int len) {
int l = 0, r = len, mid;
while (l <= r) {
mid = (l + r) >> 1;
if (target == demo[mid]) return true;
else if (target < demo[mid]) r = mid - 1;
else l = mid + 1;
}
return false;
}
int main() {
int n, ans;
while (scanf("%d", &n) ,n) {
for (int i = 0; i < n; i++)
scanf("%d%d", &demo[i].x, &demo[i].y);
sort(demo, demo + n);
ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
node tmp1, tmp2;
tmp1.x = demo[i].x + demo[i].y - demo[j].y;
tmp1.y = demo[i].y - demo[i].x + demo[j].x;
tmp2.x = demo[j].x + demo[i].y - demo[j].y;
tmp2.y = demo[j].y - demo[i].x + demo[j].x;
if (check(tmp1, n) && check(tmp2, n)) ans++;
}
}
printf("%d\n", ans >> 1);
}
return 0;
}