Captain MarmotTime
limit:MS
Memory Limit:262144KB
64bit IO Format:%i64d &%i64u SubmitStatus
Description
Captain Marmot wants to prepare a huge and important battle against his enemy, Captain Snake. For this battle he had N Regiments, each consisting of 4 moles.
Initially, each mole i (1?≤? I? ≤?4N) is placed at some position (xi,? Yi) in the Cartesian plane. Captain Marmot wants to move some moles to make the regiments compact, if it ' s possible.
Each mole i has a home placed at the Position ( a i ,? b i ) . Moving this mole one time means rotating his position point ( x i ,? Y i ) 90 degrees counter-clockwise around it's home point ( a i ,? b i ) .
A regiment is compact only if the position points of the 4 moles form a square with Non-zero area.
Help Captain Marmot to find out for each regiment the minimal number of moves required to make that regiment compact, if I T ' s possible.
Input
The first line contains one integer n (1?≤? N? ≤?100), the number of regiments.
The Next 4 n lines Contain 4 integers x i , y i , a i , b i (?-? 104?≤? X i ,? Y i ,? A i ,? b i ? ≤?104 ).
Output
Print n lines to the standard output. If the Regiment I can be made compact, the I--th line should contain one integer, the minimal number of R Equired moves. Otherwise, on the i-th line Print "-1" (without quotes).
Sample Input
Input
41 1 0 0-1 1 0 0-1 1 0 01-1 0 01 1 0 0-2 1 0 0-1 1 0 01-1 0 01 1 0 0-1 1 0 0-1 1 0 0-1 1 0 02 2 0 1-1 0 0-23 0 0-2-1 1 -2 0
Output
1-133
Hint
In the first regiment we can move once the second or the third mole.
We can ' t make the Second Regiment compact.
In the third regiment, from the last 3 moles We can move once one and twice another one.
In the Fourth regiment, we can move twice the first mole and once the third mole.
#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include < iostream> #include <sstream> #include <algorithm> #include <set> #include <queue> #include <stack> #include <map>using namespace std;typedef long long ll;const int inf=0x3f3f3f3f;const double pi= ACOs ( -1.0); #define Lson L,mid,rt<<1#define Rson mid+1,r,rt<<1|1struct Node {int x, y;} rec[10][10],cen[10]; ll dis (struct node a,struct Node B) {ll xx,yy; LL Res; xx= (a.x-b.x) * (a.x-b.x); yy= (A.Y-B.Y) * (A.Y-B.Y); Res=xx+yy; return res;} LL bian[6];//ll xie[2];void judge () {int i,j,k,l; int ans=inf; For (i=0, i<4; i++) for (j=0; j<4; j + +) for (k=0; k<4; k++) for (l=0; l<4; l++) { Bian[0]=dis (rec[i][0],rec[j][1]); Bian[1]=dis (rec[j][1],rec[k][2]); Bian[2]=dis (Rec[k][2],rec[l][3]); Bian[3]=dis (Rec[l][3],Rec[i][0]); Bian[4]=dis (rec[i][0],rec[k][2]); Bian[5]=dis (Rec[j][1],rec[l][3]); for (int ii=0;ii<6;ii++)//printf ("bian[%d]==%d", Ii,bian[ii]); Sort (bian,bian+6); if (bian[0]==0| | bian[1]==0| | bian[2]==0| | bian[3]==0| | bian[4]==0| | bian[5]==0) continue; else if (bian[0]==bian[1]&&bian[1]==bian[2]&&bian[2]==bian[3]&&bian[3]==bian[0]& &XIE[0]==XIE[1]&&BIAN[0]*2==XIE[0])//Ans=min (ANS,I+J+K+L); else if (bian[0]==bian[1]&&bian[1]==bian[2]&&bian[2]==bian[3]&&bian[3]==bian[0]& &BIAN[4]==BIAN[5]&&BIAN[0]*2==BIAN[4]) ans=min (ans,i+j+k+l); } if (Ans!=inf) printf ("%d\n", ans); else printf (" -1\n");} int main () {int t,i,j; scanf ("%d", &t); while (t--) {for (i=0; i<4; i++) {scanf ("%d%d", &rec[0][i].x,&rec[0][i].y); scanf ("%d%d", &cen[i].x,&cen[i].y); rec[1][i].x=cen[i].x-(REC[0][I].Y-CEN[I].Y); rec[1][i].y=cen[i].y+ (rec[0][i].x-cen[i].x); rec[2][i].x=cen[i].x-(rec[0][i].x-cen[i].x); rec[2][i].y=cen[i].y-(REC[0][I].Y-CEN[I].Y); rec[3][i].x=cen[i].x+ (REC[0][I].Y-CEN[I].Y); rec[3][i].y=cen[i].y-(rec[0][i].x-cen[i].x); } judge (); } return 0;}
Captain Marmot (Codeforces Round #271 div2) C