Advertisement
shek_shek

Untitled

Oct 6th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <map>
  4. #include <vector>
  5. #include <set>
  6. #include <string>
  7. #include <list>
  8. #include <cstdlib>
  9. #include <algorithm>
  10. #include <iomanip>
  11. #include <queue>
  12. #include <stack>
  13. #include <bitset>
  14. #include <cassert>
  15. #include <cmath>
  16. #include <ctime>
  17.  
  18. using namespace std;
  19.  
  20. typedef unsigned long long li;
  21. typedef long double ld;
  22. typedef pair<int, int> pt;
  23.  
  24. #define all(a) a.begin(), a.end()
  25. #define pb push_back
  26. #define mp make_pair
  27. #define forn(i,n) for (int i = 0; i < int(n); ++i)
  28.  
  29. const int INF = 1e9;
  30. const ld EPS = 1e-9;
  31.  
  32. bool read()
  33. {
  34. return true;
  35. }
  36.  
  37. int x[4], y[4], a[4], b[4];
  38.  
  39. bool inc(vector<int> &v)
  40. {
  41. int r = v.size() - 1;
  42. while (r >= 0 && ++v[r] == 4)
  43. v[r--] = 0;
  44. if (r == -1)
  45. return false;
  46. return true;
  47. }
  48.  
  49. pair<int, int> p[4];
  50.  
  51. pair<int, int> rot(pt t, int a, int b)
  52. {
  53. t.first -= a, t.second -= b;
  54. swap(t.first, t.second);
  55. t.first *= -1;
  56. t.first += a, t.second += b;
  57. return t;
  58. }
  59.  
  60. #define sqr(x) ( (x) * (x) )
  61. int dist(pair<int, int> a, pair<int, int> b)
  62. {
  63. return sqr(a.first - b.first) + sqr(a.second - b.second);
  64. }
  65.  
  66. bool sq()
  67. {
  68. vector<int> v;
  69. forn (i, 4)
  70. forn (j, i)
  71. v.pb(dist(p[i], p[j]));
  72. sort(all(v));
  73. if (v[0] == 0)
  74. return false;
  75. if (v[3] != v[0])
  76. return false;
  77. if (v[4] != v[5] || v[4] != v[0] * 2)
  78. return false;
  79. return true;
  80. }
  81.  
  82. void solve()
  83. {
  84. int n;
  85. cin >> n;
  86. forn (i, n)
  87. {
  88. forn (j, 4)
  89. cin >> x[j] >> y[j] >> a[j] >> b[j];
  90.  
  91. int ans = INF;
  92.  
  93. vector<int> v(4, 0);
  94. do
  95. {
  96. forn (j, 4)
  97. {
  98. p[j].first = x[j], p[j].second = y[j];
  99. forn (k, v[j])
  100. p[j] = rot(p[j], a[j], b[j]);
  101. }
  102. if (sq())
  103. {
  104. int cur = 0;
  105. forn (j, 4)
  106. cur += v[j];
  107. ans = min(ans, cur);
  108. }
  109. }while(inc(v));
  110. if (ans == INF)
  111. ans = -1;
  112. cout << ans << endl;
  113. }
  114. }
  115.  
  116. int main() {
  117. #ifdef _DEBUG
  118. freopen("input.txt", "r", stdin);
  119. //freopen("output.txt", "w", stdout);
  120. #endif
  121.  
  122. read();
  123. solve();
  124.  
  125. return 0;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement