题意:给一个n和n个整数坐标问这些点能组成几个不同正三角形,正方形,正五边形,正六边形。
分析:由于坐标都是整数,使用只可能有正方形,其他都不可能,那么只要对于每四个不同的点,判断2组对边相等,两条对角线也相等,临边也相等即可。
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <algorithm> #pragma comment(linker,"/STACK:1024000000,1024000000") using namespace std; const int maxn = 25; int d[2][maxn]; int main() { int n; while(scanf("%d",&n)!=EOF){ for(int i=1;i<=n;i++) scanf("%d%d",&d[0][i],&d[1][i]); int ans=0; for(int k1=1;k1<=n-3;k1++) for(int k2=k1+1;k2<=n-2;k2++) for(int k3=k2+1;k3<=n-1;k3++) for(int k4=k3+1;k4<=n;k4++){ double b1=sqrt((d[0][k1]-d[0][k2])*(d[0][k1]-d[0][k2])*1.0+(d[1][k1]-d[1][k2])*(d[1][k1]-d[1][k2]));//这三组边是对边,对边,对角线三种任意的顺序 double b2=sqrt((d[0][k3]-d[0][k4])*(d[0][k3]-d[0][k4])*1.0+(d[1][k3]-d[1][k4])*(d[1][k3]-d[1][k4])); double c1=sqrt((d[0][k1]-d[0][k3])*(d[0][k1]-d[0][k3])*1.0+(d[1][k1]-d[1][k3])*(d[1][k1]-d[1][k3])); double c2=sqrt((d[0][k2]-d[0][k4])*(d[0][k2]-d[0][k4])*1.0+(d[1][k2]-d[1][k4])*(d[1][k2]-d[1][k4])); double d1=sqrt((d[0][k1]-d[0][k4])*(d[0][k1]-d[0][k4])*1.0+(d[1][k1]-d[1][k4])*(d[1][k1]-d[1][k4])); double d2=sqrt((d[0][k2]-d[0][k3])*(d[0][k2]-d[0][k3])*1.0+(d[1][k2]-d[1][k3])*(d[1][k2]-d[1][k3])); if(b1==b2&&c1==c2&&d1==d2&&(b1==c1||b1==d1||c1==d1)) ans++; //分别判断第一组对边,第二组对边,对角线,临边相等 } printf("%d\n",ans); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-12-21 03:57:38