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\n",ans); } return 0; }