YorKnEz

Untitled

Jan 26th, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. typedef struct Punct {
  8. int l;
  9. int c;
  10. } Punct;
  11.  
  12. int n, **a, x, altcr;
  13.  
  14. Punct *coada, pct;
  15.  
  16. int dl[] = {-1, 0, 1 , 0},
  17. dc[] = {0, 1, 0 , -1};
  18.  
  19. void bordare (int **a) {
  20. for (int i = 0; i < n+2; i++) {
  21. a[i][0] = 0;
  22. a[i][n+1] = 0;
  23. a[0][i] = 0;
  24. a[n+1][i] = 0;
  25. }
  26. }
  27.  
  28. void afisare (int **a) {
  29. for (int i = 0; i <= n+1; i++) {
  30. for (int j = 0; j <= n+1; j++) {
  31. printf("%d ", a[i][j]);
  32. }
  33.  
  34. printf ("\n");
  35. }
  36.  
  37. printf ("\n");
  38. }
  39.  
  40. void lee () {
  41. int p = 0, u = 0;
  42. bool exit = false;
  43.  
  44. coada[p].l = 1;
  45. coada[p].c = 1;
  46.  
  47. while (p <= u && !exit) {
  48. if (a[coada[p].l][coada[p].c] == x) {
  49. pct.l = coada[p].l;
  50. pct.c = coada[p].c;
  51.  
  52. exit = true;
  53.  
  54. break;
  55. }
  56.  
  57. for (int i = 0; i < 4; i++) {
  58.  
  59. if (a[coada[p].l + dl[i]][coada[p].c + dc[i]] > a[coada[p].l][coada[p].c] && a[coada[p].l + dl[i]][coada[p].c + dc[i]] <= x && a[coada[p].l +dl[i]][coada[p].c + dc[i]] > altcr) {
  60. u++;
  61.  
  62. if(a[coada[p].l + dl[i]][coada[p].c + dc[i]] > altcr && a[coada[p].l + dl[i]][coada[p].c + dc[i]] <= x) {
  63. altcr = a[coada[p].l + dl[i]][coada[p].c + dc[i]];
  64. }
  65.  
  66. coada[u].l = coada[p].l + dl[i];
  67. coada[u].c = coada[p].c + dc[i];
  68. }
  69. }
  70.  
  71. //afisare(a);
  72.  
  73. p++;
  74. }
  75. }
  76.  
  77. int main()
  78. {
  79. freopen("munte1.in", "r", stdin);
  80. freopen("munte1.out", "w", stdout);
  81.  
  82. /* INPUT HERE:
  83. 4
  84. 1 3 9 10
  85. 2 4 11 13
  86. 5 6 12 14
  87. 7 15 16 19
  88. 13
  89. */
  90.  
  91. scanf("%d", &n);
  92.  
  93. //--
  94.  
  95. a = (int **) malloc (sizeof(int *) * (n + 2));
  96.  
  97. for (int i = 0; i < n+2; i++) {
  98. a[i] = (int *) malloc (sizeof(int) * (n + 2));
  99. }
  100.  
  101. coada = (Punct *) malloc (sizeof(Punct) * n * n);
  102.  
  103. bordare(a);
  104. //--
  105.  
  106. for (int i = 1; i <= n; i++) {
  107. for (int j = 1; j <= n; j++) {
  108. scanf("%d", &a[i][j]);
  109. }
  110. }
  111.  
  112. scanf("%d", &x);
  113.  
  114. //afisare(a);
  115.  
  116. lee();
  117.  
  118. printf("%d %d", pct.l, pct.c);
  119.  
  120. return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment