lmmsoft’s blog

On the way to freedom

Cf97div2 D计算几何 暴力

| Comments

//获得8个数的全排列,然后判断是否满足前四个正方形,后四个矩形,判断使用边长相等+一个直角即可

int px[10], py[10];

double dis(int a, int b) {
return (px[a] - px[b])*(px[a] - px[b])+(py[a] - py[b])*(py[a] - py[b]);
}

bool isRt(int a, int b, int c) {
return ((px[b] - px[a])*(px[c] - px[b])+(py[b] - py[a])*(py[c] - py[b]) == 0);
}

bool isSq(int a, int b, int c, int d) {
int l1 = dis(a, b);
int l2 = dis(b, c);
int l3 = dis(c, d);
int l4 = dis(a, d);
if (l1 == l2 && l2 == l3 && l3 == l4 && isRt(a, b, c))
return 1;
return 0;
}

bool isJu(int a, int b, int c, int d) {
int l1 = dis(a, b);
int l2 = dis(b, c);
int l3 = dis(c, d);
int l4 = dis(a, d);
if (l1 == l3 && l2 == l4 && isRt(a, b, c))
return 1;
return 0;
}

int main() {
for (int i = 1; i <= 8; ++i) {
scanf("%d%d", &px[i], &py[i]);
}
int sq[8] = {1, 2, 3, 4, 5, 6, 7, 8};
int flag = 0;

do {
if (isSq(sq[0], sq[1], sq[2], sq[3]) && isJu(sq[4], sq[5], sq[6], sq[7])) {
flag = 1;
printf("YES\n%d %d %d %d\n%d %d %d %d\n", sq[0], sq[1], sq[2], sq[3], sq[4], sq[5], sq[6], sq[7]);
break;
}

} while (next_permutation(sq, sq + 8));
if (!flag) {
puts("NO");
}
return 0;
}  

Comments