summaryrefslogtreecommitdiff
path: root/trees/blog/obi2018-bolas.typ
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-03-26 16:23:24 -0300
committerGabriel Schneider <[email protected]>2026-03-27 13:48:42 -0300
commit7c32657002fca2c7e2195d789b1b11e3071d79a2 (patch)
tree6ee80577abce9f16251b3b8c642ae290ad8084b7 /trees/blog/obi2018-bolas.typ
parentc5388feaf9a3bc57070af7c75d03c88bc4fbda4a (diff)
download0x4200.cafe-7c32657002fca2c7e2195d789b1b11e3071d79a2.tar.gz
0x4200.cafe-7c32657002fca2c7e2195d789b1b11e3071d79a2.zip
Squashed older blog files
Diffstat (limited to 'trees/blog/obi2018-bolas.typ')
-rw-r--r--trees/blog/obi2018-bolas.typ47
1 files changed, 47 insertions, 0 deletions
diff --git a/trees/blog/obi2018-bolas.typ b/trees/blog/obi2018-bolas.typ
new file mode 100644
index 0000000..577b1ce
--- /dev/null
+++ b/trees/blog/obi2018-bolas.typ
@@ -0,0 +1,47 @@
+#import "html_elements.typ": post
+#show: post
+
+#import "./lib.typ": flex, svg_inline
+
+
+- #link("https://olimpiada.ic.unicamp.br/pratique/ps/2018/f3/bolas/")[Enunciado].
+
+Como o tamano do vetor é #svg_inline[$8$] e temos sempre #svg_inline[$8$] números para escolher, existem #svg_inline[$8!$] permutações possíveis. Como #svg_inline[$8!$] é pequeno, podemos fazer uma solução de busca completa. Existem de varias soluções possíveis como com _next_permutation_. Segue uma solução de backtracking:
+
+```cpp
+ #include <bits/stdc++.h>
+ using namespace std;
+
+ int vet[9]={};
+
+ int solve(int pos, int n) {
+ if(pos==8) return 1;
+
+ int ans=0;
+
+ for(int i=0;i<=9;i++) {
+ if(n != i && vet[i]) {
+ vet[i]--;
+ ans|=solve(pos+1,i);
+ vet[i]++;
+ }
+ }
+
+ return ans;
+ }
+
+ int main() {
+
+ for(int i=0;i<8;i++) {
+ int aux;
+ scanf("%d",&aux);
+ vet[aux]++;
+ }
+
+ int ans=solve(0,-1);
+ puts(ans?"S":"N");
+
+ return 0;
+ }
+```
+