Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdio>
- using namespace std;
- int xx[15], yy[15], x[15], y[15], a[15], b[15];
- bool calc(int t1, int t2, int t3, int t4)
- {
- for(int i = 1; i <= 4; ++i)
- xx[i] = x[i], yy[i] = y[i];
- for(int i = 1; i <= t1; ++i)
- {
- int z = xx[1];
- xx[1] = a[1] - yy[1];
- yy[1] = z - b[1];
- }
- for(int i = 1; i <= t2; ++i)
- {
- int z = xx[2];
- xx[2] = a[2] -yy[2];
- yy[2] = z - b[2];
- }
- for(int i = 1; i <= t3; ++i)
- {
- int z = xx[3];
- xx[3] = a[3] -yy[3];
- yy[3] = z - b[3];
- }
- for(int i = 1; i <= t4; ++i)
- {
- int z = xx[4];
- xx[4] = a[4] -yy[4];
- yy[4] = z - b[4];
- }
- xx[5] = xx[1], yy[5] = yy[1];
- if(t1 == 2 && !t2 && t3 == 1 && !t4)
- {
- for(int i = 1; i <= 4; ++i)
- {
- // cout << xx[i] << ' ' << yy[i] << endl;
- }
- }
- for(int i = 1; i <= 4; ++i)
- {
- if(xx[i] * xx[i + 1] + yy[i] * yy[i + 1] != 0)
- {
- if(xx[i] != xx[i + 1] || yy[i] != yy[i + 1])
- return 0;
- }
- }
- for(int i = 1; i <= 4; ++i)
- {
- for(int j = i + 1; j <= 4; ++j)
- {
- if(xx[i] == xx[j] && yy[i] == yy[j])
- return 0;
- }
- }
- /* for(int i = 1; i <= 4; ++i)
- {
- cout << xx[i] + a[i] << ' ' << yy[i] + b[i] << endl;
- } */
- return 1;
- }
- int n;
- int main()
- {
- freopen("in", "r", stdin);
- // freopen("out", "w", stdout);
- ios::sync_with_stdio(0);
- cin.tie(0);
- cin >> n;
- for(int i = 1; i <= n; ++i)
- {
- int ans = (int)(1e9);
- for(int j = 1; j <= 4; ++j)
- {
- cin >> x[j] >> y[j] >> a[j] >> b[j];
- x[j] -= a[j], y[j] -= b[j];
- }
- for(int t1 = 0; t1 <= 3; ++ t1)
- for(int t2 = 0; t2 <= 3; ++t2)
- for(int t3 = 0; t3 <= 3; ++t3)
- for(int t4 = 0; t4 <= 3; ++t4)
- if(calc(t1, t2, t3, t4))
- {
- // cout << t1 + t2 + t3 + t3 << endl;
- ans = min(ans, t1 + t2 + t3 + t4);
- }
- cout << (ans == (int)(1e9) ? -1 : ans) << "\n";;;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement