@jpetit/toolkit 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/.prettierignore +11 -0
  2. package/.prettierrc.json +9 -0
  3. package/.vscode/settings.json +26 -0
  4. package/README.md +22 -0
  5. package/assets/lua/fixCodeBlocks.lua +19 -0
  6. package/assets/lua/removeEnvs.lua +20 -0
  7. package/assets/lua/removeHtmlOnly.lua +11 -0
  8. package/assets/problems/graphics/japanese-flag.pbm/README.md +14 -0
  9. package/assets/problems/graphics/japanese-flag.pbm/award.png +0 -0
  10. package/assets/problems/graphics/japanese-flag.pbm/handler.yml +2 -0
  11. package/assets/problems/graphics/japanese-flag.pbm/problem.ca.tex +21 -0
  12. package/assets/problems/graphics/japanese-flag.pbm/problem.ca.yml +3 -0
  13. package/assets/problems/graphics/japanese-flag.pbm/sample-1.inp +1 -0
  14. package/assets/problems/graphics/japanese-flag.pbm/sample-2.inp +1 -0
  15. package/assets/problems/graphics/japanese-flag.pbm/solution.cc +25 -0
  16. package/assets/problems/graphics/japanese-flag.pbm/solution.py +11 -0
  17. package/assets/problems/graphics/tortuga.pbm/README.md +13 -0
  18. package/assets/problems/graphics/tortuga.pbm/award.png +0 -0
  19. package/assets/problems/graphics/tortuga.pbm/handler.yml +2 -0
  20. package/assets/problems/graphics/tortuga.pbm/problem.ca.tex +23 -0
  21. package/assets/problems/graphics/tortuga.pbm/problem.ca.yml +3 -0
  22. package/assets/problems/graphics/tortuga.pbm/sample.inp +0 -0
  23. package/assets/problems/graphics/tortuga.pbm/solution.py +11 -0
  24. package/assets/problems/standard/campanar-de-la-torrassa.pbm/README.md +15 -0
  25. package/assets/problems/standard/campanar-de-la-torrassa.pbm/award.html +1 -0
  26. package/assets/problems/standard/campanar-de-la-torrassa.pbm/award.png +0 -0
  27. package/assets/problems/standard/campanar-de-la-torrassa.pbm/campanar.eps +1113 -0
  28. package/assets/problems/standard/campanar-de-la-torrassa.pbm/campanar.png +0 -0
  29. package/assets/problems/standard/campanar-de-la-torrassa.pbm/generate.cc +10 -0
  30. package/assets/problems/standard/campanar-de-la-torrassa.pbm/handler.yml +2 -0
  31. package/assets/problems/standard/campanar-de-la-torrassa.pbm/problem.ca.tex +59 -0
  32. package/assets/problems/standard/campanar-de-la-torrassa.pbm/problem.ca.yml +3 -0
  33. package/assets/problems/standard/campanar-de-la-torrassa.pbm/problem.en.tex +52 -0
  34. package/assets/problems/standard/campanar-de-la-torrassa.pbm/problem.en.yml +4 -0
  35. package/assets/problems/standard/campanar-de-la-torrassa.pbm/sample.inp +7 -0
  36. package/assets/problems/standard/campanar-de-la-torrassa.pbm/slow.cc +29 -0
  37. package/assets/problems/standard/campanar-de-la-torrassa.pbm/solution.cc +48 -0
  38. package/assets/problems/standard/campanar-de-la-torrassa.pbm/test-1.inp +12 -0
  39. package/assets/problems/standard/campanar-de-la-torrassa.pbm/test-2.inp +100000 -0
  40. package/assets/problems/standard/campanar-de-la-torrassa.pbm/test-2.ops +1 -0
  41. package/assets/problems/standard/campanar-de-la-torrassa.pbm/test-b.inp +0 -0
  42. package/assets/problems/standard/maximum-of-2-integers.pbm/README.md +11 -0
  43. package/assets/problems/standard/maximum-of-2-integers.pbm/handler.yml +1 -0
  44. package/assets/problems/standard/maximum-of-2-integers.pbm/problem.ca.tex +17 -0
  45. package/assets/problems/standard/maximum-of-2-integers.pbm/problem.ca.yml +3 -0
  46. package/assets/problems/standard/maximum-of-2-integers.pbm/problem.en.tex +16 -0
  47. package/assets/problems/standard/maximum-of-2-integers.pbm/problem.en.yml +4 -0
  48. package/assets/problems/standard/maximum-of-2-integers.pbm/sample-1.inp +1 -0
  49. package/assets/problems/standard/maximum-of-2-integers.pbm/sample-2.inp +1 -0
  50. package/assets/problems/standard/maximum-of-2-integers.pbm/sample-3.inp +1 -0
  51. package/assets/problems/standard/maximum-of-2-integers.pbm/solution.c +18 -0
  52. package/assets/problems/standard/maximum-of-2-integers.pbm/solution.cc +13 -0
  53. package/assets/problems/standard/maximum-of-2-integers.pbm/solution.java +16 -0
  54. package/assets/problems/standard/maximum-of-2-integers.pbm/solution.py +5 -0
  55. package/assets/problems/standard/maximum-of-2-integers.pbm/test-1.inp +1 -0
  56. package/assets/problems/standard/maximum-of-2-integers.pbm/test-2.inp +1 -0
  57. package/assets/problems/standard/maximum-of-2-integers.pbm/test-3.inp +1 -0
  58. package/assets/problems/standard/maximum-of-2-integers.pbm/test-4.inp +1 -0
  59. package/assets/problems/standard/maximum-of-2-integers.pbm/test-5.inp +1 -0
  60. package/assets/problems/standard/treasures-in-a-map.pbm/README.md +12 -0
  61. package/assets/problems/standard/treasures-in-a-map.pbm/atzar.cc +85 -0
  62. package/assets/problems/standard/treasures-in-a-map.pbm/award.png +0 -0
  63. package/assets/problems/standard/treasures-in-a-map.pbm/generate-1.cc +26 -0
  64. package/assets/problems/standard/treasures-in-a-map.pbm/generate-2.cc +26 -0
  65. package/assets/problems/standard/treasures-in-a-map.pbm/generate-3.cc +26 -0
  66. package/assets/problems/standard/treasures-in-a-map.pbm/generate-4.cc +26 -0
  67. package/assets/problems/standard/treasures-in-a-map.pbm/handler.yml +1 -0
  68. package/assets/problems/standard/treasures-in-a-map.pbm/problem.ca.tex +40 -0
  69. package/assets/problems/standard/treasures-in-a-map.pbm/problem.ca.yml +3 -0
  70. package/assets/problems/standard/treasures-in-a-map.pbm/problem.en.tex +40 -0
  71. package/assets/problems/standard/treasures-in-a-map.pbm/problem.en.yml +4 -0
  72. package/assets/problems/standard/treasures-in-a-map.pbm/random-1.inp +24 -0
  73. package/assets/problems/standard/treasures-in-a-map.pbm/random-2.inp +27 -0
  74. package/assets/problems/standard/treasures-in-a-map.pbm/random-3.inp +38 -0
  75. package/assets/problems/standard/treasures-in-a-map.pbm/random-4.inp +50 -0
  76. package/assets/problems/standard/treasures-in-a-map.pbm/sample-1.inp +9 -0
  77. package/assets/problems/standard/treasures-in-a-map.pbm/sample-2.inp +6 -0
  78. package/assets/problems/standard/treasures-in-a-map.pbm/sample-3.inp +7 -0
  79. package/assets/problems/standard/treasures-in-a-map.pbm/solution.cc +38 -0
  80. package/assets/problems/standard/treasures-in-a-map.pbm/test-1.inp +5 -0
  81. package/assets/problems/standard/treasures-in-a-map.pbm/test-2.inp +6 -0
  82. package/assets/problems/standard/treasures-in-a-map.pbm/test-3.inp +6 -0
  83. package/assets/problems/standard/treasures-in-a-map.pbm/test-4.inp +9 -0
  84. package/assets/problems/standard/treasures-in-a-map.pbm/test-5.inp +10 -0
  85. package/assets/problems/standard/treasures-in-a-map.pbm/test-6.inp +9 -0
  86. package/assets/problems/standard/treasures-in-a-map.pbm/test-7.inp +12 -0
  87. package/assets/problems/standard/treasures-in-a-map.pbm/test-8.inp +3 -0
  88. package/assets/problems/standard/treasures-in-a-map.pbm/test-9.inp +37 -0
  89. package/assets/problems/standard/treasures-in-a-map.pbm/test-91.inp +52 -0
  90. package/assets/problems/standard/treasures-in-a-map.pbm/test-92.inp +25 -0
  91. package/assets/problems/standard/treasures-in-a-map.pbm/test-93.inp +3 -0
  92. package/assets/sty/judgeit.ca.sty +54 -0
  93. package/assets/sty/judgeit.de.sty +61 -0
  94. package/assets/sty/judgeit.en.sty +60 -0
  95. package/assets/sty/judgeit.es.sty +54 -0
  96. package/assets/sty/judgeit.fr.sty +59 -0
  97. package/assets/sty/judgeit.sty +307 -0
  98. package/assets/sty/picins.sty +579 -0
  99. package/assets.zip +0 -0
  100. package/eslint.config.mjs +31 -0
  101. package/lib/ai.ts +138 -0
  102. package/lib/assets.ts +31 -0
  103. package/lib/cleaner.ts +58 -0
  104. package/lib/compilers/_frompython.ts +388 -0
  105. package/lib/compilers/base.ts +97 -0
  106. package/lib/compilers/gcc.ts +47 -0
  107. package/lib/compilers/gxx.ts +47 -0
  108. package/lib/compilers/index.ts +61 -0
  109. package/lib/compilers/python3.ts +67 -0
  110. package/lib/data.ts +19 -0
  111. package/lib/doctor.ts +104 -0
  112. package/lib/generate.ts +333 -0
  113. package/lib/maker.ts +535 -0
  114. package/lib/settings.ts +42 -0
  115. package/lib/tui.ts +69 -0
  116. package/lib/utils.ts +83 -0
  117. package/package.json +56 -0
  118. package/problems/graphic.pbm/README.md +14 -0
  119. package/problems/graphic.pbm/award.png +0 -0
  120. package/problems/graphic.pbm/handler.yml +2 -0
  121. package/problems/graphic.pbm/problem.ca.html +13 -0
  122. package/problems/graphic.pbm/problem.ca.md +20 -0
  123. package/problems/graphic.pbm/problem.ca.tex +21 -0
  124. package/problems/graphic.pbm/problem.ca.txt +20 -0
  125. package/problems/graphic.pbm/problem.ca.yml +3 -0
  126. package/problems/graphic.pbm/sample-1.inp +1 -0
  127. package/problems/graphic.pbm/sample-2.inp +1 -0
  128. package/problems/graphic.pbm/solution.py +11 -0
  129. package/problems/maxim2.pbm/Main.java +13 -0
  130. package/problems/maxim2.pbm/distillation.yml +7 -0
  131. package/problems/maxim2.pbm/distilled-01.inp +1 -0
  132. package/problems/maxim2.pbm/distilled-02.inp +1 -0
  133. package/problems/maxim2.pbm/distilled-03.inp +1 -0
  134. package/problems/maxim2.pbm/distiller.yml +2 -0
  135. package/problems/maxim2.pbm/generate-inputs.py +9 -0
  136. package/problems/maxim2.pbm/handler.yml +2 -0
  137. package/problems/maxim2.pbm/ma-1.inp +1 -0
  138. package/problems/maxim2.pbm/ma-2.inp +1 -0
  139. package/problems/maxim2.pbm/ma-3.inp +1 -0
  140. package/problems/maxim2.pbm/ma-4.inp +1 -0
  141. package/problems/maxim2.pbm/ma-5.inp +1 -0
  142. package/problems/maxim2.pbm/per-doubles.inp +1 -0
  143. package/problems/maxim2.pbm/problem.ca.html +11 -0
  144. package/problems/maxim2.pbm/problem.ca.md +19 -0
  145. package/problems/maxim2.pbm/problem.ca.tex +17 -0
  146. package/problems/maxim2.pbm/problem.ca.txt +19 -0
  147. package/problems/maxim2.pbm/problem.ca.yml +3 -0
  148. package/problems/maxim2.pbm/problem.en.html +11 -0
  149. package/problems/maxim2.pbm/problem.en.md +19 -0
  150. package/problems/maxim2.pbm/problem.en.tex +16 -0
  151. package/problems/maxim2.pbm/problem.en.txt +19 -0
  152. package/problems/maxim2.pbm/problem.en.yml +4 -0
  153. package/problems/maxim2.pbm/sample-1.inp +1 -0
  154. package/problems/maxim2.pbm/sample-2.inp +1 -0
  155. package/problems/maxim2.pbm/sample-3.inp +1 -0
  156. package/problems/maxim2.pbm/solution.c +12 -0
  157. package/problems/maxim2.pbm/solution.cc +13 -0
  158. package/problems/maxim2.pbm/solution.java +13 -0
  159. package/problems/maxim2.pbm/solution.pas +9 -0
  160. package/problems/maxim2.pbm/solution.py +5 -0
  161. package/problems/maxim2.pbm/tags.yml +2 -0
  162. package/problems/maxim2.pbm/test_-1_-1.inp +1 -0
  163. package/problems/maxim2.pbm/test_-1_-2.inp +1 -0
  164. package/problems/maxim2.pbm/test_-1_0.inp +1 -0
  165. package/problems/maxim2.pbm/test_-1_1.inp +1 -0
  166. package/problems/maxim2.pbm/test_-2_-1.inp +1 -0
  167. package/problems/maxim2.pbm/test_-2_-2.inp +1 -0
  168. package/problems/maxim2.pbm/test_-2_0.inp +1 -0
  169. package/problems/maxim2.pbm/test_-2_1.inp +1 -0
  170. package/problems/maxim2.pbm/test_0_-1.inp +1 -0
  171. package/problems/maxim2.pbm/test_0_-2.inp +1 -0
  172. package/problems/maxim2.pbm/test_0_0.inp +1 -0
  173. package/problems/maxim2.pbm/test_0_1.inp +1 -0
  174. package/problems/maxim2.pbm/test_1_-1.inp +1 -0
  175. package/problems/maxim2.pbm/test_1_-2.inp +1 -0
  176. package/problems/maxim2.pbm/test_1_0.inp +1 -0
  177. package/problems/maxim2.pbm/test_1_1.inp +1 -0
  178. package/test.ts +3 -0
  179. package/toolkit/ai.ts +30 -0
  180. package/toolkit/clean.ts +19 -0
  181. package/toolkit/compilers.ts +29 -0
  182. package/toolkit/create-jutge-ai.ts +101 -0
  183. package/toolkit/create-template.ts +51 -0
  184. package/toolkit/create-wizard.ts +4 -0
  185. package/toolkit/create.ts +75 -0
  186. package/toolkit/doctor.ts +17 -0
  187. package/toolkit/index.ts +28 -0
  188. package/toolkit/init.ts +66 -0
  189. package/toolkit/make.ts +60 -0
  190. package/toolkit/verify.ts +19 -0
  191. package/tsconfig.json +38 -0
  192. package/types/zip.d.ts +4 -0
@@ -0,0 +1,11 @@
1
+ # Maximum of two integers
2
+
3
+ ## Features
4
+
5
+ - Standard problem: read input and write output
6
+ - Statements in multiple languages
7
+ - Solutions in multiple programming languages
8
+
9
+ ## Abstract
10
+
11
+ Given two integers, determine and output the larger of the two.
@@ -0,0 +1,17 @@
1
+ \Problem{Màxim de dos enters}
2
+
3
+
4
+ \Statement
5
+
6
+ Feu un programa que llegeixi dos nombres i que n'escrigui el màxim.
7
+
8
+ \Input
9
+
10
+ L'entrada consisteix en dos enters.
11
+
12
+ \Output
13
+
14
+ Cal escriure una línia amb el màxim dels dos nombres.
15
+
16
+ \Sample
17
+
@@ -0,0 +1,3 @@
1
+ email: jpetit@cs.upc.edu
2
+ title: Màxim de dos enters
3
+ author: Jordi Petit
@@ -0,0 +1,16 @@
1
+
2
+ \Problem{Maximum of two integer numbers}
3
+
4
+ \Statement
5
+
6
+ Write a program that reads two numbers and prints their maximum.
7
+
8
+ \Input
9
+
10
+ Input consists of two integer numbers.
11
+
12
+ \Output
13
+
14
+ Print a line with the maximum of the two numbers.
15
+
16
+ \Sample
@@ -0,0 +1,4 @@
1
+ translator: Carlos Molina
2
+ title: Maximum of two integers
3
+ translator_email: cmolinah@gmail.com
4
+ original_language: ca
@@ -0,0 +1,18 @@
1
+ #include <stdio.h>
2
+
3
+ int main()
4
+ {
5
+ int a, b;
6
+
7
+ (void)scanf("%d", &a);
8
+ (void)scanf("%d", &b);
9
+
10
+ if (a > b)
11
+ {
12
+ printf("%d\n", a);
13
+ }
14
+ else
15
+ {
16
+ printf("%d\n", b);
17
+ }
18
+ }
@@ -0,0 +1,13 @@
1
+ #include <iostream>
2
+ using namespace std;
3
+
4
+ int main()
5
+ {
6
+ int a, b;
7
+ cin >> a >> b;
8
+ if (a > b) {
9
+ cout << a << endl;
10
+ } else {
11
+ cout << b << endl;
12
+ }
13
+ }
@@ -0,0 +1,16 @@
1
+ import java.util.*;
2
+
3
+ class Main {
4
+
5
+ public static void main(String[] args) {
6
+ Scanner scanner = new Scanner(System.in);
7
+ int a = scanner.nextInt();
8
+ int b = scanner.nextInt();
9
+ if (a > b) {
10
+ System.out.println(a);
11
+ } else {
12
+ System.out.println(b);
13
+ }
14
+ }
15
+
16
+ }
@@ -0,0 +1,5 @@
1
+ from yogi import read
2
+
3
+ a = read(int)
4
+ b = read(int)
5
+ print(max(a, b))
@@ -0,0 +1 @@
1
+ 987654321 -987654321
@@ -0,0 +1,12 @@
1
+ # Treasures in a map
2
+
3
+ ## Features
4
+
5
+ - Standard problem: read input and write output
6
+ - Statements in multiple languages
7
+ - Award in .`png`
8
+ - Random testcases generators
9
+
10
+ ## Abstract
11
+
12
+ Count the number of treasures in a map represented as a grid of characters.
@@ -0,0 +1,85 @@
1
+ // atzar.cc
2
+ // SR, febrer/06
3
+ // Implementacio d'una classe per treballar amb nombres aleatoris.
4
+
5
+
6
+ #include <vector>
7
+ #include <algorithm>
8
+ using namespace std;
9
+
10
+
11
+ class atzar {
12
+ private:
13
+
14
+ int llavor;
15
+ void seguent();
16
+
17
+ public:
18
+
19
+ // inicialitza la llavor amb el valor donat
20
+ atzar(int llavor);
21
+
22
+ // retorna un real aleatori de [0, 1)
23
+ double uniforme();
24
+
25
+ // retorna un enter aleatori de [esquerra, dreta]
26
+ int uniforme(int esquerra, int dreta);
27
+
28
+ // retorna un real aleatori de [esquerra, dreta] amb dig digits
29
+ double uniforme(int esquerra, int dreta, int dig);
30
+
31
+ // retorna true amb probabilitat p
32
+ bool probabilitat(double p);
33
+
34
+ // retorna una permutaci� aleat�ria de 0 .. n - 1
35
+ vector<int> permutacio(int n);
36
+ };
37
+
38
+
39
+ atzar::atzar(int llavor) : llavor(llavor) { }
40
+
41
+
42
+ void atzar::seguent() {
43
+ int x1, x0, z, z1, z0, w, w1, w0;
44
+ x1 = llavor/65536L; x0 = llavor&65535L;
45
+ z = 1894L*x0; z1 = z/65536L; z0 = z&65535L;
46
+ w = 27319L*x1; w1 = w/32768L; w0 = w&32767L;
47
+ llavor = 453816693L + 1894L*x1 + z1 + w1 - 2147483647L;
48
+ llavor += 27319L*x0;
49
+ if (llavor >= 0L) llavor -= 2147483647L;
50
+ llavor += 32768L*z0;
51
+ if (llavor >= 0L) llavor -= 2147483647L;
52
+ llavor += 65536L*w0;
53
+ if (llavor < 0L) llavor += 2147483647L;
54
+ }
55
+
56
+
57
+ double atzar::uniforme() {
58
+ seguent();
59
+ return (double)llavor/(double)2147483647L;
60
+ }
61
+
62
+
63
+ int atzar::uniforme(int esquerra, int dreta) {
64
+ return esquerra + (int)(((double)(dreta - esquerra + 1))*uniforme());
65
+ }
66
+
67
+
68
+ double atzar::uniforme(int esquerra, int dreta, int dig) {
69
+ int pow = 1;
70
+ while (dig--) pow *= 10;
71
+ return ((double)uniforme(esquerra*pow, dreta*pow))/(double)pow;
72
+ }
73
+
74
+
75
+ bool atzar::probabilitat(double p) {
76
+ return uniforme() < p;
77
+ }
78
+
79
+
80
+ vector<int> atzar::permutacio(int n) {
81
+ vector<int> V(n);
82
+ for (int i = 0; i < n; ++i) V[i] = i;
83
+ for (int i = n - 1; i > 0; --i) swap(V[i], V[uniforme(0, i)]);
84
+ return V;
85
+ }
@@ -0,0 +1,26 @@
1
+ #include "atzar.cc"
2
+ #include <iostream>
3
+ #include <vector>
4
+ using namespace std;
5
+
6
+
7
+ atzar A(0);
8
+
9
+
10
+ int main() {
11
+ int n = A.uniforme(1, 100);
12
+ int m = A.uniforme(1, 100);
13
+ cout << n << ' ' << m << endl;
14
+
15
+ int x = A.uniforme(1, n);
16
+ int y = A.uniforme(1, m);
17
+
18
+ for (int i = 1; i <= n; ++i) {
19
+ for (int j = 1; j <= m; ++j)
20
+ if ((i == x and j == y) or A.probabilitat(0.6)) cout << '.';
21
+ else cout << (A.probabilitat(0.04) ? 't' : 'X');
22
+ cout << endl;
23
+ }
24
+
25
+ cout << x << ' ' << y << endl;
26
+ }
@@ -0,0 +1,26 @@
1
+ #include "atzar.cc"
2
+ #include <iostream>
3
+ #include <vector>
4
+ using namespace std;
5
+
6
+
7
+ atzar A(1);
8
+
9
+
10
+ int main() {
11
+ int n = A.uniforme(1, 100);
12
+ int m = A.uniforme(1, 100);
13
+ cout << n << ' ' << m << endl;
14
+
15
+ int x = A.uniforme(1, n);
16
+ int y = A.uniforme(1, m);
17
+
18
+ for (int i = 1; i <= n; ++i) {
19
+ for (int j = 1; j <= m; ++j)
20
+ if ((i == x and j == y) or A.probabilitat(0.6)) cout << '.';
21
+ else cout << (A.probabilitat(0.04) ? 't' : 'X');
22
+ cout << endl;
23
+ }
24
+
25
+ cout << x << ' ' << y << endl;
26
+ }
@@ -0,0 +1,26 @@
1
+ #include "atzar.cc"
2
+ #include <iostream>
3
+ #include <vector>
4
+ using namespace std;
5
+
6
+
7
+ atzar A(5);
8
+
9
+
10
+ int main() {
11
+ int n = A.uniforme(1, 100);
12
+ int m = A.uniforme(1, 100);
13
+ cout << n << ' ' << m << endl;
14
+
15
+ int x = A.uniforme(1, n);
16
+ int y = A.uniforme(1, m);
17
+
18
+ for (int i = 1; i <= n; ++i) {
19
+ for (int j = 1; j <= m; ++j)
20
+ if ((i == x and j == y) or A.probabilitat(0.5)) cout << '.';
21
+ else cout << (A.probabilitat(0.05) ? 't' : 'X');
22
+ cout << endl;
23
+ }
24
+
25
+ cout << x << ' ' << y << endl;
26
+ }
@@ -0,0 +1,26 @@
1
+ #include "atzar.cc"
2
+ #include <iostream>
3
+ #include <vector>
4
+ using namespace std;
5
+
6
+
7
+ atzar A(9);
8
+
9
+
10
+ int main() {
11
+ int n = A.uniforme(1, 100);
12
+ int m = A.uniforme(1, 100);
13
+ cout << n << ' ' << m << endl;
14
+
15
+ int x = A.uniforme(1, n);
16
+ int y = A.uniforme(1, m);
17
+
18
+ for (int i = 1; i <= n; ++i) {
19
+ for (int j = 1; j <= m; ++j)
20
+ if ((i == x and j == y) or A.probabilitat(0.6)) cout << '.';
21
+ else cout << (A.probabilitat(0.04) ? 't' : 'X');
22
+ cout << endl;
23
+ }
24
+
25
+ cout << x << ' ' << y << endl;
26
+ }
@@ -0,0 +1,40 @@
1
+
2
+ \Problem{Tresors en un mapa}
3
+
4
+ \Statement
5
+
6
+ Feu un programa que, donat un mapa amb tresors i obstacles,
7
+ digui si és possible o no arribar fins a algun dels tresors
8
+ des d'una posició inicial donada.
9
+ Els moviments permesos són horitzontals o verticals,
10
+ però no diagonals.
11
+ Si cal, es pot passar per sobre dels tresors.
12
+
13
+
14
+ \Input
15
+
16
+ L'entrada comença amb el nombre de files $n$ i de columnes $m$ del mapa.
17
+ Segueixen $n$ files amb $m$ caràcters cadascuna.
18
+ Un punt indica una posició buida,
19
+ una \texttt{'X'} indica un obstacle,
20
+ i una \texttt{'t'} indica un tresor.
21
+ Finalment, un parell de nombres $f$ i $c$
22
+ indiquen la fila i columna inicials (ambdues començant en 1)
23
+ des de les quals cal començar a buscar tresors.
24
+ Podeu suposar que $n > 0$, que $m > 0$,
25
+ que $f$ estarà entre 1 i $n$, que $c$ estarà entre 1 i $m$,
26
+ i que la posició inicial sempre estarà lliure.
27
+
28
+
29
+ \Output
30
+
31
+ Escriviu \texttt{"1"} o \texttt{"0"}
32
+ depenent de si és possible o no arribar a algun dels tresors.
33
+
34
+
35
+ \Observation
36
+
37
+ La manera més senzilla de resoldre aquest exercici no usa cap cua.
38
+
39
+
40
+ \SampleTwoCol
@@ -0,0 +1,3 @@
1
+ email: roura@lsi.upc.edu
2
+ author: Salvador Roura
3
+ title: Tresors en un mapa (1)
@@ -0,0 +1,40 @@
1
+
2
+ \Problem{Treasures in a map}
3
+
4
+ \Statement
5
+
6
+ Write a program that, given a map with treasures and obstacles,
7
+ indicates if is possible or not to arrive to any treasure
8
+ from a given initial position.
9
+ The allowed movements are horizontal or vertical,
10
+ but not diagonal.
11
+ If it is necessary, passing over the treasures is allowed.
12
+
13
+
14
+ \Input
15
+
16
+ Input starts with the number of rows $n$ and the number of columns $m$ of the map.
17
+ $n$ rows follow with $m$ characters each one.
18
+ A dot indicates an empty position,
19
+ a \texttt{'X'} indicates an obstacle,
20
+ and a \texttt{'t'} indicates a treasure.
21
+ Finally, a pair of numbers $r$ and $c$
22
+ indicates the initial row and column (both of them starting with 1)
23
+ where your program must start to look for the treasures.
24
+ You can suppose that $n > 0$, that $m > 0$,
25
+ that $r$ will be between 1 and $n$, that $c$ will be between 1 and $m$,
26
+ and that the initial position will be always in an empty position.
27
+
28
+
29
+ \Output
30
+
31
+ Your program must print \texttt{"1"} or \texttt{"0"}
32
+ depending on if it possible or not to arrive to any treasure.
33
+
34
+
35
+ \Observation
36
+
37
+ The simplest way to solve this exercise does not use any queue.
38
+
39
+
40
+ \SampleTwoCol
@@ -0,0 +1,4 @@
1
+ translator: Carlos Molina
2
+ translator_email: cmolinah@gmail.com
3
+ original_language: ca
4
+ title: Treasures in a map (1)
@@ -0,0 +1,24 @@
1
+ 22 31
2
+ .XX....X.X.....X.X.X.X....XX.X.
3
+ X..X....X.XXX...........XX..X..
4
+ ...XXX....tX......X....XX.tXXX.
5
+ X.X....XXXXXX.X.X........X...XX
6
+ X..X...XX..XXX...X..XX....X.X..
7
+ XXt..XXXX.X..X.XXX...X.X....XX.
8
+ X.X.X.X..XXX.XX...X.X.XX.X.X...
9
+ .X..XXX........X.X....XXXX..X.X
10
+ .X..XXX.......XXXX..........X.X
11
+ XXXX..X...X.t.XX.X....XX...X...
12
+ X.X..X.X.X..X.X.XX.X..X..Xt...X
13
+ .X.X...X...XX...X.X.X....X.....
14
+ ..XX..X.XXX...XXX....t.X.X.X.XX
15
+ .XXXX....X...XXX.X.XXt.XX..X...
16
+ .X.XX.XX...XX..X.XXXX..X.X....X
17
+ X.X.X.XX.XXX..XX.X.X.........XX
18
+ ...XXXX..X.XX..t..X......X...X.
19
+ X.X..X......XX...XX........X..X
20
+ .X...XX.XX.tX.X..XX...X....X..X
21
+ ...X...X....XXX..XXXX..XX.X..t.
22
+ X.X.XXXX.XX.tXX..XXX.XX.XX..XX.
23
+ ..X.XX..XX....X.XXXX.X........X
24
+ 19 30
@@ -0,0 +1,27 @@
1
+ 25 71
2
+ ...X.X.XXXXX.XXX.XX..XXXXX.XXX.X.X..X.XX..XX.X..X...t....X.XX.....X....
3
+ .X..X...........X..XX.X.X.tXX.XX....X...XX.XtX..X..XXX...X.X.X.X..XXX..
4
+ XX.X..X.X.X.XXXX...X.XXXX......XX..XXX.X....XX..X.....XXXX...XX.X.XXXX.
5
+ ..XX..XXXX.....X.XXX.XX.X....X...X.......X...X.X..X..XX..X.....XXX.X...
6
+ .X......XXXXXX..XX.XXt.XtXX.XXXX...XX.XXX..XX..X...X....X.XXXX.XXXX.X.X
7
+ XX..X...X.X.X...X..t.XX.X..X........XX....X...tXXX...XXXXX..X..XX.....X
8
+ XX.X...X.X..XX..X.X.X.X...X...XXXX.XXXX.XXX..X.....XX..X.X......X......
9
+ .X.X...X..X.XX......X....XXX.X.XXXtXX.XXXX...XXX.XtXt..XX.tXX.XXX.t.X..
10
+ .XXX.X..XX.....X..XX...X...X.XX.X..X.X...X....X.X.XXXX......XXX..X...XX
11
+ X...XX.X..X...X..X....X.X...X.XXt.X..XXX.X..XX...X.X...X...XXX..X......
12
+ ..XXX.X....tX...X......X.X..X.....X..X..XXX.XX.X...XX...X.....X..X.XXX.
13
+ XX...tX..X....XX....XXXX....X.X...XX.X..XX.X.t.t.....X.X...X....X.XX...
14
+ XX.XXXX.X.X.XX...X..X....XXXXX...XX.........X....X..X.X..X.XXX.......X.
15
+ ..XtX..X.......XXXX.X.XX..X...XX..XX..XXX....X.X.....X..XXX.X.XXX...X..
16
+ X.X.X....X.....XX.......X.....XX.XX..X......t.X..X...X.....XX.X.X..X...
17
+ ....X.X.....X..XXXXX...X.XX..X....X.....XXXX..X.X......XX.XXX...X..X.XX
18
+ X.XXX...t.XX..X.XXX...X..X..X.t..X.X.....XX..X.t..XX..XXX.X.X.X....X.X.
19
+ ......XX.......X.XX..X..X.X.....X.XXX..X...X.X.XX..X.....X.XXX..t.XX..X
20
+ .X.X.XX..XX.X.XXX...Xt...X..........XX....XXX..XX...X...XXXXXX.X.XXXX..
21
+ ..XX.X..XXX..XXX.XX....X....X......X..X...X.X..XX..X..X.XXXX.XXX..XX.XX
22
+ ..XX......X..X..XXX.X.X...X..X.XXX.tXX......XX.X....X.X....XX.....X..Xt
23
+ ..XX.X..XX.XX..XXXXX..XX.X...X.X..X.XX.X..XX..X..............XX..XX..X.
24
+ .X...XX....XXXXXX..XX.X...X...X.X......X.XXX.X.X....XX....X......XXXt..
25
+ ....tt......X..XX.X..XXX.X...XX.XXXX.X.XXXXXX............X.X.XX....X...
26
+ XX..XX...X......X.XtXX.XXX...XXX.XX.X..XXXXX.XX..XX.X...XXXXX..XX.X....
27
+ 8 62
@@ -0,0 +1,38 @@
1
+ 36 28
2
+ XX.X.X.....X..X...X....XX.XX
3
+ X.XX...XXX.X...X.X..X...X.X.
4
+ X..XtX.X...XX..X...XXX.X....
5
+ X.XXtX.X.XXXX....XX..X....XX
6
+ ..XXX...XX.XX.t...XX....X..X
7
+ ..XX..X.XX...X....X.X.XXXXXX
8
+ X....XXX.X..X..XX.t..XXXXXXX
9
+ ..X..XXX.X..XX...XX.X.X.XXXX
10
+ XX..XXX..X.X.X.t.XX.XXX..XX.
11
+ XX......X.X..XX..XX.X.XXXXXX
12
+ XX.XX.X.X..X...XXX..X.X..XX.
13
+ XXtX...X..XXXX...X.XX.XXXXXX
14
+ .XXXXX..XXX.X.X..XXX..X..XX.
15
+ .XXX.XX...XX...X..XX.tX..XX.
16
+ .X..XX.X.....X.XXX.XX.X...X.
17
+ X....X...X..X..X..X....X.X..
18
+ .X..X.X...XX.X..XXXX..X.....
19
+ XXX.......Xt.XXXXX.X.XX...XX
20
+ .X..X...X....XXX.X......X..X
21
+ X.X.....X..X..XX.XX.....XXX.
22
+ X..X.XXXX.X.X.X.Xt.XXXXX....
23
+ X..X.XXX.XX..XXXXX.XX..X.X..
24
+ ..X.X..X.....XXX..X.X.XXX.XX
25
+ XX.XXtX..XX...X....XX.XX.X.X
26
+ ..tXXX.t.X.X.X..X.X.XX.X..X.
27
+ X...XXX..X..X.XXXX.XX...X..X
28
+ X.X.XXX...XX.XX.XXX....X.XXX
29
+ XX....X..X.XXXX....XXXXXXX..
30
+ X..X.X..X...XXXX..X...XX....
31
+ t..XXX.XXX.XXXX.X...XX.tX.X.
32
+ tXX.t.....X.X.X....XX..XXX.X
33
+ ..X.XXX...XtX.X.X..X.XX..X.t
34
+ XXXX.X.XXXtXX..X..X.XtXXXXX.
35
+ .X.Xt...Xt..t..XXXX.XX..X...
36
+ X.XXXX.XXX...X.XX.XXX...X.XX
37
+ ..XXX.X..XXXXXtX..X..X..X.X.
38
+ 11 15
@@ -0,0 +1,50 @@
1
+ 48 86
2
+ .XXXXX...XXX..XX.......XX.XXX.XX..X..XX.X.XX....XX....XX..XX.XX.X..X..X.X.X..X....XX..
3
+ ...X.t.X.tXXXX.X.X...X.X.X..XX...XX.X.X......X.XXX.X.X.t.XXX...X.X..X..XXX.XX....X..XX
4
+ ..X...X..XX....X.X.....X.XXX.XX...XX..XX...X.X.X..X....XX...XXX...X.X.....XX.XXX....XX
5
+ ..X...XXXXX.XXXX.XXX.XXXX..X....XX.X.XX.XXX....XXX..t....X......X.X..X..X..X..X..X.XXX
6
+ X...XX..X.XX.X..XXX...t..X.X.X..X...X.t...XXX.X...X....X.X..X..X.X....X.X.XX....X....X
7
+ ....XX.X.XXXXX....X.X.XX.X.X......XX...X.XXXXX.X.....XX.X..X.XX.....XX..X.X.XX.XX.X.X.
8
+ X.XXX..XX.XXXXXXX.X..Xt..XXXXt..XX..X.X..X.XX.X.X....X...XXXX..XX..X......XX.....X.X.X
9
+ ...X..t.XX..XXX....X..X.XX...XX...X...X.XX.X....X.X...X....XXX.X.X.XXXX.XX.XXX.X..XX..
10
+ .X...X..X.XX.XX....X.t....XX....XXX.X..XX.XXX..X.X....XX..X..X...X.XX.X..XX.......X...
11
+ ....XXXX.XX.X.X..XX.X.X.X.X.X..XXXX...X.t...XX.....XX.X.XX....X.X.....X.X..........X.X
12
+ X.........X.....X..X........XXXXXXXX.X..X..X.XX.XX.X.X.t.X.X....X...XX.....X.X.t......
13
+ .t.XX..X.....X.X...X.XX.t...XX...X.X....XX...XX.X..X.X.XX.XXX...X.......X.X.XX.X..XX.X
14
+ .X...X.....X..X.XX....X.....XX...X.XXXX..X.tXXX.........XX..XX......XXXXXX..XXXX.XXX.X
15
+ ..X........X.X..X....XX.X.XX..XX..X...XX.XX.X...X..X...X..X.X.XXXX.XX...XX..X......X..
16
+ ...X.XX.....X.XX...XX..X.XX.X.X..XXX..XXX.......X......X.....XX.X.X.X.XXXX..XXXXX.X...
17
+ ...XX.XXXX.tX......X...X...........X........XXX.X.XX.XXXX..tX..X...X.X..XX.X..X...X.X.
18
+ .X........X..XXXX.......X.X..XXX.X...XX.X......X.....X......X.....XXXXXX.t.XX.....X...
19
+ .............XX.X.XXX....XXX....XXX...X...X.X..X...X.X...X...X.XXX....X.....XXX..XXXXX
20
+ ...X....X.XX........X..XX.XX.X...XX.X...XX.XX.....X.XX.....X...X.XX.XXXX..XX.XX......X
21
+ X.XXX...XX.XXX...X..X..X..XXXXX.X..X..XX....X....XX..XXX.X..X....X...X.....XXX..XXt...
22
+ .X.XXXX.XX.XX......X.....XX..X..X.XX.X.X.XXX..X....X..XX..XXX..X.....X.XXX..XX.XX.X..X
23
+ ..X..X.XX......XXXtXXXXXXX....X.X....X....XX..........X..X.......X..XXX.XX..X.......X.
24
+ ...XX.X.............X....X..X....X.XXX.X....X..XXXX.XX..X.XXX..XXX.X.X.......XX.X.XXXX
25
+ X..XXXX....XXX.Xt..X...X.X.....XX..XX.X.X.....XtX..X.XX.....X.XXtX......XXX.XX...XX...
26
+ ..XXXXX....X.....X.X.X..XX.XX...X.XXX.XX.t.X.XX....XX.X.X.X..XXX..XX.tX..X...X...XXXXX
27
+ XX.X.X..XXX.X...X...........X.......XtXXXX.X....XX..X..X...XX.X.X..X...X...X....XX..X.
28
+ X..XX..XXX.X..XXX.X.X..X.X...X..X.XXX.X....XX....X.X.XXX.XXXX.......X.X.......X......X
29
+ .XXXX.XX.X...t.....XX....XXX..X.....X..X.........X...XXXXtXXXX.....X.XX.X....X..X.XXX.
30
+ ..X.XX.XX.t...............XX...X.X....XX.X...X.X.....X..XXX..X..XXXX...XXtX.XX.XX.....
31
+ ...XtX..X...X.X......X.XX...X.XXXXX.XX.....XX.XX..XX....X...X.XXtXX.......X..XX.XXX.X.
32
+ X..X........X.X...X.X.X.X.X.X...X.XXX.Xt..t.X.X......X.......XX....t.XX...X.X..XXt.X.X
33
+ XX.XXXX..X.XXXX.XX..X.....X.....XX.X.X..XX..t.X..X..X.......XX......X.X.X..X.XXX.X.X.X
34
+ ...X...XXXXXXXXXXX...Xt....XX..X...X.XXX.X.XX.XX......X..X....X.X.XX..tX....X..X.X.X..
35
+ .XX.X....X.............XX..XXX.....X..XtX.X...X...X.t.X..X.X....XXX...X...X....X...XXX
36
+ ....X..X.XXXXX.X.X.XXX.X..X...X...........X...XX..X...X.XX..XX........XX.......X......
37
+ ..XXt..XXX..X.X.X...XXXX.....X.X...XXX.XX.X.X.X...XX..XX....XX....X..X...XX..X.XX..X..
38
+ ........X.X.X.X...X...X.X.XXXX..X...X..XXX..XX.....X.XX......XXX.X.XX..XXX....X..XXX.X
39
+ X.XXX.......XX.X.XX.X.X...XX..X....XXXX.....t..X.....t...X.X.Xt.XX...X.X..t.XX...XX...
40
+ ....X...XXX..X.XX.XX.X..X.XX.X.X...X..X.X.....X....XX.X.......XXX...XX..X..X.XX....X..
41
+ .XX.XXXXXX.XXX.X.X.XX.....X....X..XX.XX.....X..XX...X..t.X...X.XX...XXX..XXX.X.......X
42
+ X........XXXX..XXX.X.X..X.X..XX..X.t...XX....X...XX.X.....X...X...XXX.tX...X.Xt.X.X..X
43
+ ....XXX.X.XX..XX....X...X..XX......XX.......X.XXX...XXX...XX.XXX...X..XXX....XXX.....X
44
+ ..X.Xt..X.Xt.....X......X......X....X..XX.XXX........XXXX....X.X.XXXXX.....XXX.XX.X...
45
+ ......X..X....X.XXX...tXX.X..XXX.X..XX...XX.X......t....X.X.X...X.X..XXXX....XX..XX...
46
+ ...X.XX......X.X.X..X.....X.XXXXXX...Xt....XX...X.XX.XX.X....X..XX...X.X.X.XXXX..X..X.
47
+ X..X...X...X.............X....X.XX...XXXX...X..XXX....X........XX.X.X............XX.X.
48
+ Xt.X.XX..XXXX..XX..X....XXX.XX...X...XXX..XX...X..X...XXX.XX.XXX.X.XXXX.X.XX....X.X...
49
+ XX.X..X.X....X.X.XXXX.XXXXX.X..X.X.X.X...XXX.XX..Xt......X..X..X.X....X..X...X..X.XX..
50
+ 14 13
@@ -0,0 +1,9 @@
1
+ 7 6
2
+ ..t...
3
+ ..XXX.
4
+ ......
5
+ tX..X.
6
+ .X..Xt
7
+ .XX...
8
+ ..t...
9
+ 5 3
@@ -0,0 +1,6 @@
1
+ 4 10
2
+ ..t...X...
3
+ .....X..t.
4
+ XXXXX.X...
5
+ .......X.t
6
+ 4 1
@@ -0,0 +1,7 @@
1
+ 5 7
2
+ .......
3
+ .XXXXXt
4
+ .X...Xt
5
+ .X.X.XX
6
+ ...X.Xt
7
+ 5 5
@@ -0,0 +1,38 @@
1
+ #include <iostream>
2
+ #include <vector>
3
+ using namespace std;
4
+
5
+
6
+ typedef vector<char> VC;
7
+ typedef vector<VC> VVC;
8
+ typedef vector<bool> VB;
9
+ typedef vector<VB> VVB;
10
+
11
+
12
+ bool busca(int f, int c, int n, int m, const VVC& mapa, VVB& vist) {
13
+ if (f < 0 or f >= n or c < 0 or c >= m or vist[f][c]) return false;
14
+
15
+ vist[f][c] = true;
16
+ if (mapa[f][c] == 't') return true;
17
+ if (mapa[f][c] == 'X') return false;
18
+
19
+ return busca(f + 1, c, n, m, mapa, vist)
20
+ or busca(f - 1, c, n, m, mapa, vist)
21
+ or busca(f, c + 1, n, m, mapa, vist)
22
+ or busca(f, c - 1, n, m, mapa, vist);
23
+ }
24
+
25
+
26
+ int main() {
27
+ int n, m;
28
+ cin >> n >> m;
29
+ VVC mapa(n, VC(m));
30
+ for (int i = 0; i < n; ++i)
31
+ for (int j = 0; j < m; ++j) cin >> mapa[i][j];
32
+ int f, c;
33
+ cin >> f >> c;
34
+
35
+ VVB vist(n, VB(m, false));
36
+ if (busca(f - 1, c - 1, n, m, mapa, vist)) cout << "1" << endl;
37
+ else cout << "0" << endl;
38
+ }