题目链接:点击打开链接
题意:
给定T表示case数
以下4行是一个case
每行2个点,u v
每次u能够绕着v逆时针转90°
问最少操作多少次使得4个u构成一个正方形。
思路:
枚举判可行
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;
int hah,ijj;
int haifei;
template <class T>
inline bool rd(T &ret) {char c; int sgn;if(c=getchar(),c==EOF) return 0;while(c!='-'&&(c<'0'||c>'9')) c=getchar();sgn=(c=='-')?
-1:1; ret=(c=='-')?
0:(c-'0'); while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); ret*=sgn; return 1; } template <class T> inline void pt(T x) { if (x <0) { putchar('-'); x = -x; } if(x>9) pt(x/10); putchar(x%10+'0'); } /// const double eps = 1e-8; const double pi = acos(-1.0); struct node { double x, y; }; bool dcmp(double i, double j) { return fabs(i - j) <= eps; } bool eq(const node& i, const node& j) { return dcmp(i.x, j.x) && dcmp(i.y, j.y); } /* x0= (x - rx0)*cos(a) - (y - ry0)*sin(a) + rx0 ; y0= (x - rx0)*sin(a) + (y - ry0)*cos(a) + ry0 ; */ node turn(const node& i, const node& j, double a) { node re; re.x= (i.x - j.x)*cos(a) - (i.y - j.y)*sin(a) + j.x; re.y= (i.x - j.x)*sin(a) + (i.y - j.y)*cos(a) + j.y; return re; } bool cc(const node& i, const node& j) { if (!dcmp(i.x, j.x)) return i.x < j.x; else return i.y < j.y; } double sqr(double x) { return x * x; } double D(node i, node j) { return sqr(i.x-j.x) + sqr(i.y-j.y); } double dis[20]; int idx; bool ok(node i, node j, node k, node z) { node ar[4]; ar[0]=i; ar[1]=j; ar[2]=k; ar[3]=z; idx = 0; for (int i = 0; i < 4; ++i) for (int j = i + 1; j < 4; ++j) dis[idx++]=D(ar[i],ar[j]); sort(dis, dis +idx); if (dcmp(dis[0], dis[3]) && !dcmp(dis[0], 0) && dcmp(dis[4], dis[5]) && dcmp(dis[0] * 2, dis[4])) { return true; } else return false; } int main() { node a[10], b[10]; int T; rd(T); while (T -- > 0) { for (int i = 0; i < 4; ++i) scanf("%lf%lf%lf%lf", &a[i].x, &a[i].y, &b[i].x, &b[i].y); int ans = 100; for (int i = 0; i < 4; ++i) for (int j = 0; j < 4; ++j) for (int k = 0; k < 4; ++k) for (int l = 0; l < 4; ++l) if (ok(turn(a[0], b[0], i*pi/2),turn(a[1], b[1], j*pi/2), turn(a[2], b[2], k*pi/2),turn(a[3], b[3], l*pi/2))) { ans = min(i+j+k+l, ans); } if (ans == 100) ans = -1; pt(ans); putchar('\n'); } return 0; }