POJ 2002

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#define MAXN 1111
using namespace std;
class Point{
    public:
        int x,y;
        bool operator < (const Point &p) const{
            if(x == p.x) return y < p.y;
            return x < p.x;
        }
        bool operator == (const Point &p) const{
            return x == p.x && y == p.y;
        }
};
Point P[MAXN];
bool Binary_Search(const Point target,int len){
    int l = 0,r = len,mid;
    while(l <= r){
        mid = (l+r) >> 1;
        if(target == P[mid]) return true;
        else if(target < P[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",&P[i].x,&P[i].y);
        sort(P,P+n);
        ans = 0;
        for(int i = 0;i < n;i ++){
            for(int j = i+1;j < n;j ++){
                Point tmp1,tmp2;
                tmp1.x = P[i].x+P[i].y-P[j].y,tmp1.y = P[i].y-P[i].x+P[j].x;
                tmp2.x = P[j].x+P[i].y-P[j].y,tmp2.y = P[j].y-P[i].x+P[j].x;
                if(Binary_Search(tmp1,n) && Binary_Search(tmp2,n)) ans++;
            }
        }
        printf("%d\n",ans >> 1);
    }
    return 0;
}


posted on 2014-04-30 18:39  wangzhili  阅读(119)  评论(0编辑  收藏  举报