Codeforces 474C Captain Marmot 给定4个点和各自旋转中心 问旋转成正方形的次数
題目鏈接:點(diǎn)擊打開鏈接
題意:
給定T表示case數(shù)
以下4行是一個case
每行2個點(diǎn),u v
每次u能夠繞著v逆時針轉(zhuǎn)90°
問最少操作多少次使得4個u構(gòu)成一個正方形。
思路:
枚舉判可行
-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; }
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎
總結(jié)
以上是生活随笔為你收集整理的Codeforces 474C Captain Marmot 给定4个点和各自旋转中心 问旋转成正方形的次数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。