zoukankan      html  css  js  c++  java
  • hdu 5365 Run

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    
    int n;
    int x[30],y[30];
    
    class Coordinate
    {
    public:
        double xCoordinate;
        double yCoordinate;
    
        Coordinate(double x = 0,double y = 0)
        {
            this->xCoordinate = x;
            this->yCoordinate = y;
        }
    
        bool operator!=(Coordinate const &comp) const
        {
            return (this->xCoordinate != comp.xCoordinate ||
                    this->yCoordinate != comp.yCoordinate);
        }
    }tp[10];
    
    
    bool Judge(Coordinate const x,Coordinate const y,Coordinate const z)
    {
        Coordinate *mVector = new Coordinate(x.xCoordinate - y.xCoordinate,
                                            x.yCoordinate - y.yCoordinate);
        Coordinate *nVector = new Coordinate(z.xCoordinate -
                                            (x.xCoordinate + y.xCoordinate)/2,
                                             z.yCoordinate -
                                             (x.yCoordinate + y.yCoordinate)/2);
        bool result = ((mVector->xCoordinate * nVector->xCoordinate +
                        mVector->yCoordinate * nVector->yCoordinate) == 0);
    
        if(result)
            result = (mVector->xCoordinate * mVector->xCoordinate +
                    mVector->yCoordinate * mVector->yCoordinate)
                     == ((nVector->xCoordinate * nVector->xCoordinate +
                        nVector->yCoordinate * nVector->yCoordinate) * 4);
    
        delete mVector;
        delete nVector;
    
        return result;
    }
    
    
    bool IsSquare(Coordinate *tp,int length)
    {
        if(length != 4)
            return false;
        int a,b,c;
    
        if(Judge(tp[0],tp[1],tp[2]))
        {
            a = 0;
            b = 1;
            c = 2;
        }
        else if(Judge(tp[0],tp[2],tp[1]))
        {
            a = 0;
            b = 2;
            c = 1;
        }
        else if(Judge(tp[2],tp[1],tp[0]))
        {
            a = 1;
            b = 2;
            c = 0;
        }
        else
            return false;
    
        return (tp[3] != tp[c] && Judge(tp[a],tp[b],tp[3]));
    }
    
    int main()
    {
        while(~scanf("%d",&n)){
        int ans=0;
        for(int i=0;i<n;i++)
            scanf("%d%d",&x[i],&y[i]);
        for(int a=0;a<n;a++)
            for(int b=a+1;b<n;b++)
                for(int c=b+1;c<n;c++)
                    for(int d=c+1;d<n;d++)
                    {
                        tp[0].xCoordinate=x[a];tp[0].yCoordinate=y[a];
                        tp[1].xCoordinate=x[b];tp[1].yCoordinate=y[b];
                        tp[2].xCoordinate=x[c];tp[2].yCoordinate=y[c];
                        tp[3].xCoordinate=x[d];tp[3].yCoordinate=y[d];
                        if(IsSquare(tp,4)) ans++;
                    }
        printf("%d
    ",ans);
        }
        return 0;
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

  • 相关阅读:
    一个Package Load Failed问题的解决方法

    .NET相关的最好东西--全球最新评价
    一年了...
    MSBuild 的简单入门
    开发基于.NET Compact Framework的程序时, 常遇到的问题(2) 为什么在Visual Studio 2003调试程序时不能通过ActiveSync连接PDA
    如何:显示用逗号分隔的项集合(摘自MSDN)
    每日一句(2008.10.8)
    每日一句(2008.10.16)
    男人这辈子
  • 原文地址:https://www.cnblogs.com/xryz/p/4847846.html
Copyright © 2011-2022 走看看