Last active
February 12, 2025 02:43
-
-
Save eduardoklosowski/4c22ea94619312d8590e9b3fbfa989fd to your computer and use it in GitHub Desktop.
Beecrowd #1414 - Copa do Mundo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"provenance": [] | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"# Resolvendo problema [#1414 - Copa do Mundo](https://resources.beecrowd.com/repository/UOJ_1414.html)" | |
], | |
"metadata": { | |
"id": "ljyNT49b7qhG" | |
} | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"## Inicia SymPy" | |
], | |
"metadata": { | |
"id": "ce8BzVz_3VxS" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"id": "NSuV85z_2vqJ" | |
}, | |
"outputs": [], | |
"source": [ | |
"from sympy import *\n", | |
"\n", | |
"init_printing()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"## Variáveis\n", | |
"\n", | |
"- `p`: Total de pontos\n", | |
"- `n`: Número de jogos\n", | |
"- `v`: Número de vitórias\n", | |
"- `e`: Número de empates" | |
], | |
"metadata": { | |
"id": "XtbJWGy32-UV" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"p, n, v, e = symbols('p n v e')" | |
], | |
"metadata": { | |
"id": "f7a7NAyc2-s6" | |
}, | |
"execution_count": 2, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"## Relações" | |
], | |
"metadata": { | |
"id": "qeRje0K76Z15" | |
} | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"### Relação entre o número de jogos, vitórias e empates" | |
], | |
"metadata": { | |
"id": "CJTdiVqR3xQf" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"equacao_jogos = Eq(n, v + e)\n", | |
"equacao_jogos" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 38 | |
}, | |
"id": "HvYopC9i3doy", | |
"outputId": "1f2358c9-1b51-4bd4-8bc1-c43487250dbb" | |
}, | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"n = e + v" | |
], | |
"text/latex": "$\\displaystyle n = e + v$" | |
}, | |
"metadata": {}, | |
"execution_count": 3 | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"### Relação da pontuação" | |
], | |
"metadata": { | |
"id": "4VOhKq5V3364" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"equacao_pontos = Eq(p, 3 * v + 2 * e)\n", | |
"equacao_pontos" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 38 | |
}, | |
"id": "R7lRqS-q37Qo", | |
"outputId": "3ff4a3e3-c319-46e9-c4bf-c3faddf5d47a" | |
}, | |
"execution_count": 4, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"p = 2⋅e + 3⋅v" | |
], | |
"text/latex": "$\\displaystyle p = 2 e + 3 v$" | |
}, | |
"metadata": {}, | |
"execution_count": 4 | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"## Resolvendo exemplos" | |
], | |
"metadata": { | |
"id": "MgeOvs-37Kmi" | |
} | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"### Exemplo 1" | |
], | |
"metadata": { | |
"id": "1dXnsugJ7kVf" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"solve([\n", | |
" equacao_jogos,\n", | |
" equacao_pontos,\n", | |
" Eq(n, 3),\n", | |
" Eq(p, 9),\n", | |
"])[e]" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 37 | |
}, | |
"id": "ndNjM5MQ7NXK", | |
"outputId": "d3166cfa-c7ca-4e35-8ec6-e630825cc881" | |
}, | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"0" | |
], | |
"text/latex": "$\\displaystyle 0$" | |
}, | |
"metadata": {}, | |
"execution_count": 5 | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"### Exemplo 2" | |
], | |
"metadata": { | |
"id": "bB7wm54N7m7O" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"solve([\n", | |
" equacao_jogos,\n", | |
" equacao_pontos,\n", | |
" Eq(n, 3),\n", | |
" Eq(p, 7),\n", | |
"])[e]" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 37 | |
}, | |
"id": "P4IpFpH47aZd", | |
"outputId": "f471106d-c504-4dbb-b638-34cb8bef1223" | |
}, | |
"execution_count": 6, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"2" | |
], | |
"text/latex": "$\\displaystyle 2$" | |
}, | |
"metadata": {}, | |
"execution_count": 6 | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment