Advertisement
Guest User

Untitled

a guest
Oct 6th, 2014
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. using namespace std;
  4. int xx[15], yy[15], x[15], y[15], a[15], b[15];
  5. bool calc(int t1, int t2, int t3, int t4)
  6. {
  7. for(int i = 1; i <= 4; ++i)
  8. xx[i] = x[i], yy[i] = y[i];
  9. for(int i = 1; i <= t1; ++i)
  10. {
  11. int z = xx[1];
  12. xx[1] = a[1] - yy[1];
  13. yy[1] = z - b[1];
  14. }
  15. for(int i = 1; i <= t2; ++i)
  16. {
  17. int z = xx[2];
  18. xx[2] = a[2] -yy[2];
  19. yy[2] = z - b[2];
  20. }
  21. for(int i = 1; i <= t3; ++i)
  22. {
  23. int z = xx[3];
  24. xx[3] = a[3] -yy[3];
  25. yy[3] = z - b[3];
  26. }
  27. for(int i = 1; i <= t4; ++i)
  28. {
  29. int z = xx[4];
  30. xx[4] = a[4] -yy[4];
  31. yy[4] = z - b[4];
  32. }
  33. xx[5] = xx[1], yy[5] = yy[1];
  34. if(t1 == 2 && !t2 && t3 == 1 && !t4)
  35. {
  36. for(int i = 1; i <= 4; ++i)
  37. {
  38. // cout << xx[i] << ' ' << yy[i] << endl;
  39. }
  40. }
  41. for(int i = 1; i <= 4; ++i)
  42. {
  43. if(xx[i] * xx[i + 1] + yy[i] * yy[i + 1] != 0)
  44. {
  45. if(xx[i] != xx[i + 1] || yy[i] != yy[i + 1])
  46. return 0;
  47. }
  48. }
  49. for(int i = 1; i <= 4; ++i)
  50. {
  51. for(int j = i + 1; j <= 4; ++j)
  52. {
  53. if(xx[i] == xx[j] && yy[i] == yy[j])
  54. return 0;
  55. }
  56. }
  57. /* for(int i = 1; i <= 4; ++i)
  58. {
  59. cout << xx[i] + a[i] << ' ' << yy[i] + b[i] << endl;
  60. } */
  61. return 1;
  62. }
  63. int n;
  64. int main()
  65. {
  66. freopen("in", "r", stdin);
  67. // freopen("out", "w", stdout);
  68. ios::sync_with_stdio(0);
  69. cin.tie(0);
  70. cin >> n;
  71. for(int i = 1; i <= n; ++i)
  72. {
  73. int ans = (int)(1e9);
  74. for(int j = 1; j <= 4; ++j)
  75. {
  76. cin >> x[j] >> y[j] >> a[j] >> b[j];
  77. x[j] -= a[j], y[j] -= b[j];
  78. }
  79. for(int t1 = 0; t1 <= 3; ++ t1)
  80. for(int t2 = 0; t2 <= 3; ++t2)
  81. for(int t3 = 0; t3 <= 3; ++t3)
  82. for(int t4 = 0; t4 <= 3; ++t4)
  83. if(calc(t1, t2, t3, t4))
  84. {
  85. // cout << t1 + t2 + t3 + t3 << endl;
  86. ans = min(ans, t1 + t2 + t3 + t4);
  87. }
  88. cout << (ans == (int)(1e9) ? -1 : ans) << "\n";;;
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement