Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int liczenie_odleglosci_plus(int x, int y, int dx, int dy)
  6. {
  7. return abs(dx - x) + abs(dy - y);
  8. }
  9.  
  10. int liczenie_odleglosci_iksplus(int x, int y, int dx, int dy)
  11. {
  12. return max(abs(dx - x),abs(dy - y));
  13. }
  14.  
  15. int main()
  16. {
  17. int ile;
  18. cin >> ile;
  19. for (int k = 0; k < ile; k++)
  20. {
  21. int wymiar;
  22. cin >> wymiar;
  23. int rozmiar;
  24. cin >> rozmiar;
  25. int utozsamianie;
  26. cin >> utozsamianie;
  27. int typ_krola;
  28. cin >> typ_krola;
  29. int suma;
  30. suma = 0;
  31. int centralny = (rozmiar + 1) / 2;
  32. if (wymiar == 2)
  33. {
  34. if (typ_krola == 0)
  35. {
  36. switch (utozsamianie)
  37. {
  38. case 0:
  39. for (int i = 0; i < rozmiar; i++)
  40. {
  41. for (int j = 0; j < rozmiar; j++)
  42. {
  43. for (int di = 0; di < rozmiar; di++)
  44. {
  45. for (int dj = 0; dj < rozmiar; dj++)
  46. {
  47. suma += liczenie_odleglosci_plus(i, j, di, dj);
  48. }
  49. }
  50. cout << suma << endl;
  51. }
  52. }
  53. break;
  54. case 1:
  55. for (int j = 0; j < rozmiar; j++)
  56. {
  57. for (int di = 0; di < rozmiar; di++)
  58. {
  59. for (int dj = 0; dj < rozmiar; dj++)
  60. {
  61. suma += liczenie_odleglosci_plus(centralny, j, di, dj);
  62. }
  63. }
  64. }
  65. break;
  66. case 2:
  67. for (int di = 0; di < rozmiar; di++)
  68. {
  69. for (int dj = 0; dj < rozmiar; dj++)
  70. {
  71. suma += liczenie_odleglosci_plus(centralny, centralny, di, dj);
  72. }
  73. }
  74. break;
  75. }
  76. cout << suma / (rozmiar*rozmiar*(rozmiar*rozmiar - 1)) << endl;
  77. }
  78. }
  79. }
  80. system("pause");
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement