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);
        }
    }array[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 *array,int length)
    {
        if(length != 4)
            return false;
        int a,b,c;
    
        if(Judge(array[0],array[1],array[2]))
        {
            a = 0;
            b = 1;
            c = 2;
        }
        else if(Judge(array[0],array[2],array[1]))
        {
            a = 0;
            b = 2;
            c = 1;
        }
        else if(Judge(array[2],array[1],array[0]))
        {
            a = 1;
            b = 2;
            c = 0;
        }
        else
            return false;
    
        return (array[3] != array[c] && Judge(array[a],array[b],array[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++)
                    {
                        array[0].xCoordinate=x[a];array[0].yCoordinate=y[a];
                        array[1].xCoordinate=x[b];array[1].yCoordinate=y[b];
                        array[2].xCoordinate=x[c];array[2].yCoordinate=y[c];
                        array[3].xCoordinate=x[d];array[3].yCoordinate=y[d];
                        if(IsSquare(array,4)) ans++;
                    }
        printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    python---1
    20190802—list、range、extend函数
    20190802—def定义函数
    20190802—import函数调用
    如何在EXCEL中将多个单元格内容合并到一个单元格中
    20190619—return函数的用法
    20190618—位置参数、默认参数、不定长参数
    excel 怎么计算单元格个数
    20190616——and和or使用方法、python运算符总结、python数据类型
    20190616——enumerate的用法
  • 原文地址:https://www.cnblogs.com/zufezzt/p/4714500.html
Copyright © 2011-2022 走看看