• POJ -- 2002


     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<string>
     5 #include<algorithm>
     6 #define MAXN 1111
     7 using namespace std;
     8 class Point{
     9     public:
    10         int x,y;
    11         bool operator < (const Point &p) const{
    12             if(x == p.x) return y < p.y;
    13             return x < p.x;
    14         }
    15         bool operator == (const Point &p) const{
    16             return x == p.x && y == p.y;
    17         }
    18 };
    19 Point P[MAXN];
    20 bool Binary_Search(const Point target,int len){
    21     int l = 0,r = len,mid;
    22     while(l <= r){
    23         mid = (l+r) >> 1;
    24         if(target == P[mid]) return true;
    25         else if(target < P[mid]) r = mid-1;
    26         else l = mid+1;
    27     }
    28     return false;
    29 }
    30 int main(){
    31     int n,ans;
    32     freopen("in.c","r",stdin);
    33     while(~scanf("%d",&n) && n){
    34         for(int i = 0;i < n;i ++) scanf("%d%d",&P[i].x,&P[i].y);
    35         sort(P,P+n);
    36         ans = 0;
    37         for(int i = 0;i < n;i ++){
    38             for(int j = i+1;j < n;j ++){
    39                 Point tmp1,tmp2;
    40                 tmp1.x = P[i].x+P[i].y-P[j].y,tmp1.y = P[i].y-P[i].x+P[j].x;
    41                 tmp2.x = P[j].x+P[i].y-P[j].y,tmp2.y = P[j].y-P[i].x+P[j].x;
    42                 if(Binary_Search(tmp1,n) && Binary_Search(tmp2,n)) ans++;
    43             }
    44         }
    45         printf("%d
    ",ans >> 1);
    46     }
    47     return 0;
    48 }
  • 相关阅读:
    字符编码
    visual studio 2015 安装记录和问题修复
    TCP状态转换图的理解
    静态库与动态库的编译链接
    运行库glibc
    堆栈的简单认识
    Makefile学习总结
    关于STM32单片机的IAP实现
    ubuntu12.0.4安装启动后无法进入图形操作界面
    观察者模式
  • 原文地址:https://www.cnblogs.com/anhuizhiye/p/3673312.html
Copyright © 2020-2023  润新知