zoukankan      html  css  js  c++  java
  • POJ 2002 二分 计算几何

    根据正方形对角的两顶点求另外两个顶点公式:

    x2 = (x1+x3-y3+y1)/2; y2 = (x3-x1+y1+y3)/2;

    x4= (x1+x3+y3-y1)/2; y4 = (-x3+x1+y1+y3)/2;

    #include<cstdio>  
    #include<cstring>  
    #include<algorithm>  
    using namespace std;  
    const int maxn=1000+5;  
    struct Node  
    {  
        int x,y;  
        bool operator<(const Node& rhs)const  
        {  
            return x<rhs.x || (x==rhs.x && y<rhs.y);  
        }  
    }nodes[maxn];  
      
    int main()  
    {  
        int n;  
        while(scanf("%d",&n)==1 && n)  
        {  
            int ans=0;//正方形个数  
            for(int i=0;i<n;++i)  
                scanf("%d%d",&nodes[i].x,&nodes[i].y);  
            sort(nodes,nodes+n);  
      
            for(int i=0;i<n;++i)  
            for(int j=i+1;j<n;++j)  
            {  
                Node tmp;//tmp作为正方形的第3或4个点  
                tmp.x=nodes[i].x+nodes[i].y-nodes[j].y;  
                tmp.y=nodes[i].y+nodes[j].x-nodes[i].x;  
                if(!binary_search(nodes,nodes+n,tmp)) continue;  
                tmp.x=nodes[j].x+nodes[i].y-nodes[j].y;  
                tmp.y=nodes[j].y+nodes[j].x-nodes[i].x;  
                if(!binary_search(nodes,nodes+n,tmp)) continue;  
                ++ans;  
            }  
            printf("%d
    ",ans/2);
        }  
        return 0;  
    } 
  • 相关阅读:
    php curl getinfo
    php 实现树形结构
    E时代主机,其实做一个小虚拟主机还是不错的
    php 生成验证码
    php curl
    nodejs 操作mysql
    php ++a和a++
    nodejs上传图片并显示的例子
    json
    Rock,Paper,Scissors 水NOJ 1090
  • 原文地址:https://www.cnblogs.com/pach/p/7502219.html
Copyright © 2011-2022 走看看