Advertisement
Falexom

Untitled

May 29th, 2022
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. #include<iostream>
  2. #include<string.h>
  3. #include<stdio.h>
  4.  
  5. using namespace std;
  6.  
  7. #define L 900
  8. #define R 8100
  9. int arr[L][R];
  10. int mas[L][R];
  11.  
  12. int zap(int a[L][R], int n)
  13. {
  14. for (int i = 0; i < L; i++)
  15. {
  16. for (int j = 0; j < R; j++)
  17. {
  18. a[i][j] = n;
  19. }
  20. }
  21. return 0;
  22. }
  23.  
  24.  
  25. int istrue(int a, int b)
  26. {
  27. if (arr[a][b]!=-1)
  28. {
  29. return arr[a][b];
  30. }
  31. if (a==0 && b==0)
  32. {
  33. arr[a][b] = 0;
  34. }
  35. else if (a==0 || b==0)
  36. {
  37. arr[a][b] = 101;
  38. return arr[a][b];
  39. }
  40. else if (a > b)
  41. {
  42. arr[a][b] = 101;
  43. return arr[a][b];
  44. }
  45. arr[a][b] = 101;
  46. return -1;
  47. }
  48.  
  49. int fun(int a, int b)
  50. {
  51.  
  52. int c;
  53. for (int i = 1; i <= 9; ++i)
  54. {
  55. printf("%d %d %d\n", i, a, b);
  56. if (a-i >= 0)
  57. {
  58. if (b - i*i >= 0)
  59. {
  60. cout << "flag" << endl;
  61. c = istrue(a-i, b-i*i);
  62. printf("%d\n", c);
  63. if (c == -1)
  64. {
  65. c = fun(a-i, b-i*i);
  66. }
  67. if (c + 1 < arr[a][b])
  68. {
  69. mas[a][b] = i;
  70. arr[a][b] = c+1;
  71. }
  72. }
  73. }
  74. }
  75. return arr[a][b];
  76. }
  77.  
  78. int check(int a, int b)
  79. {
  80. if (a > b || a >= b)
  81. {
  82. printf("No solution");
  83. printf("\n");
  84.  
  85. return 0;
  86. }
  87. if (a > L)
  88. {
  89. cout << "a<L" << endl;
  90. printf("No solution");
  91. printf("\n");
  92. return 0;
  93. }
  94. if (b > R)
  95. {
  96. cout << "b>R" << endl;
  97. printf("No solution");
  98. printf("\n");
  99. return 0;
  100. }
  101. }
  102.  
  103. int main()
  104. {
  105. zap(arr, 0);
  106. zap(mas, 0);
  107. int n;
  108. scanf("%d",&n);
  109. if (n > 10000)
  110. {
  111. return 0;
  112. }
  113. for (int i = 0; i < n; i++)
  114. {
  115. int a, b;
  116. cin >> a >> b;
  117. int res = 0;
  118. check(a, b);
  119. res = fun(a, b);
  120. if (res > 1)
  121. {
  122. while (res > 1)
  123. {
  124. printf("%d",mas[a][b]);
  125. a -= mas[a][b];
  126. b -= mas[a][b]*mas[a][b];
  127. }
  128. }
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement