Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <map>
- #include <vector>
- #include <set>
- #include <string>
- #include <list>
- #include <cstdlib>
- #include <algorithm>
- #include <iomanip>
- #include <queue>
- #include <stack>
- #include <bitset>
- #include <cassert>
- #include <cmath>
- #include <ctime>
- using namespace std;
- typedef unsigned long long li;
- typedef long double ld;
- typedef pair<int, int> pt;
- #define all(a) a.begin(), a.end()
- #define pb push_back
- #define mp make_pair
- #define forn(i,n) for (int i = 0; i < int(n); ++i)
- const int INF = 1e9;
- const ld EPS = 1e-9;
- bool read()
- {
- return true;
- }
- int x[4], y[4], a[4], b[4];
- bool inc(vector<int> &v)
- {
- int r = v.size() - 1;
- while (r >= 0 && ++v[r] == 4)
- v[r--] = 0;
- if (r == -1)
- return false;
- return true;
- }
- pair<int, int> p[4];
- pair<int, int> rot(pt t, int a, int b)
- {
- t.first -= a, t.second -= b;
- swap(t.first, t.second);
- t.first *= -1;
- t.first += a, t.second += b;
- return t;
- }
- #define sqr(x) ( (x) * (x) )
- int dist(pair<int, int> a, pair<int, int> b)
- {
- return sqr(a.first - b.first) + sqr(a.second - b.second);
- }
- bool sq()
- {
- vector<int> v;
- forn (i, 4)
- forn (j, i)
- v.pb(dist(p[i], p[j]));
- sort(all(v));
- if (v[0] == 0)
- return false;
- if (v[3] != v[0])
- return false;
- if (v[4] != v[5] || v[4] != v[0] * 2)
- return false;
- return true;
- }
- void solve()
- {
- int n;
- cin >> n;
- forn (i, n)
- {
- forn (j, 4)
- cin >> x[j] >> y[j] >> a[j] >> b[j];
- int ans = INF;
- vector<int> v(4, 0);
- do
- {
- forn (j, 4)
- {
- p[j].first = x[j], p[j].second = y[j];
- forn (k, v[j])
- p[j] = rot(p[j], a[j], b[j]);
- }
- if (sq())
- {
- int cur = 0;
- forn (j, 4)
- cur += v[j];
- ans = min(ans, cur);
- }
- }while(inc(v));
- if (ans == INF)
- ans = -1;
- cout << ans << endl;
- }
- }
- int main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- #endif
- read();
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement