├── .gitignore ├── Contests ├── Algar 2019 │ └── d.cpp ├── Aquecimento da OBI - Fase Nacional 2018 │ ├── A.cpp │ ├── B.cpp │ └── Primo.java ├── Codeforces │ ├── div2 │ │ └── 573 │ │ │ ├── a.cpp │ │ │ ├── b.cpp │ │ │ ├── c.cpp │ │ │ └── d.cpp │ ├── educational │ │ └── 68-1194-div2 │ │ │ ├── a.cpp │ │ │ ├── b.cpp │ │ │ ├── c.cpp │ │ │ └── d.cpp │ └── gym │ │ └── 247576 │ │ ├── a.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ ├── f.cpp │ │ ├── g.cpp │ │ ├── h(Ygor).cpp │ │ ├── h.cpp │ │ ├── j(Ygor).cpp │ │ ├── k.cpp │ │ ├── l.cpp │ │ ├── m.cpp │ │ └── n(Ygor).cpp ├── Contest Made by Woman URI │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ ├── F.cpp │ └── G.cpp ├── Contest Natal URI 2018 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ ├── F.cpp │ └── H.cpp ├── Facebook Hacker Cup 2019 │ └── a.cpp ├── Final Nacional da XXIII Maratona SBC de Programação 2018 │ ├── A.cpp │ └── L.cpp ├── GEOLIP - 2 │ ├── a.cpp │ ├── b.cpp │ ├── c.cpp │ ├── d.cpp │ ├── e.cpp │ ├── f.cpp │ ├── g.cpp │ ├── h.cpp │ ├── i.cpp │ ├── j.cpp │ ├── k.cpp │ ├── l.cpp │ └── m.cpp ├── GEOLIP │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ ├── F.cpp │ └── G.cpp ├── Maratona Inatel 2019 │ ├── .vscode │ │ └── ipch │ │ │ └── ba2e4fe17b08f308 │ │ │ └── KEPARTICIONANDO.ipch │ ├── A(SAMUEL).cpp │ ├── a.cpp │ ├── b.cpp │ ├── c.cpp │ ├── d.cpp │ ├── e(SAMUEL).cpp │ ├── f.cpp │ ├── h.cpp │ ├── i(NO).cpp │ ├── i(SAMUEL).cpp │ ├── j.cpp │ ├── k.cpp │ └── prova.pdf ├── Maratona Norte 2019 │ ├── Editorial III MdP do Norte by Dabriel.pdf │ └── Prova___III_MdP_do_Norte(1).pdf ├── Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2018 │ ├── 2862.cpp │ ├── 2863.cpp │ ├── 2864.cpp │ ├── 2866.cpp │ ├── 2867.cpp │ ├── 2868.cpp │ └── 2872.cpp ├── Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2019 │ ├── c.cpp │ ├── f.cpp │ ├── g.cpp │ ├── h.cpp │ ├── i.cpp │ ├── j.cpp │ ├── k.cpp │ └── solucoes-samuel │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── B_junior.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── D_junior.cpp │ │ ├── E.cpp │ │ ├── F.cpp │ │ ├── G.cpp │ │ ├── H.cpp │ │ ├── I.cpp │ │ ├── J.cpp │ │ ├── K.cpp │ │ ├── L.cpp │ │ ├── L_junior.cpp │ │ └── Soluções OLIP 2019.pdf ├── V Maratona Norte Mineira de Programação Open Contest │ ├── .vscode │ │ └── launch.json │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ ├── Editorial - Maratona Mineira de Programação 2018.pdf │ ├── F.cpp │ ├── G.cpp │ ├── H.cpp │ ├── J.cpp │ ├── L.cpp │ ├── Resoluções │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ ├── G.cpp │ │ ├── H.cpp │ │ ├── I.cpp │ │ ├── J.cpp │ │ ├── K.cpp │ │ ├── inputf.in │ │ └── outputf.in │ ├── inputf.in │ └── outputf.in ├── VII Maratona Mineira de Programação - Open Contest │ ├── #Template.cpp │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ ├── F.cpp │ ├── G.cpp │ ├── H.cpp │ ├── I.cpp │ ├── J.cpp │ └── K.cpp └── VTEX Cup 2019 │ ├── a.cpp │ ├── b.cpp │ ├── c.cpp │ ├── d.cpp │ ├── e.cpp │ ├── f.cpp │ ├── h.cpp │ ├── i.cpp │ ├── j.cpp │ ├── k.cpp │ └── l.cpp ├── Notebook ├── codes │ ├── cin_cout_foreach.cpp │ ├── divisao-conquista │ │ ├── exponencial.cpp │ │ ├── fatorial.cpp │ │ ├── fibonnaci.cpp │ │ └── hanoi.cpp │ ├── estruturas │ │ ├── alterar_tamanho_vector.cpp │ │ ├── apagar_elementos_duplicados_vector.cpp │ │ ├── apagar_primeiro_elemento_vector.cpp │ │ ├── apagar_ultimo_elemento_vector.cpp │ │ ├── arvore_indexacao_binaria.cpp │ │ ├── arvore_segmentos.cpp │ │ ├── busca_vector.cpp │ │ ├── criando_pair_com_dois_valores.cpp │ │ ├── definicao_pair.cpp │ │ ├── fila.cpp │ │ ├── fila_prioridades.cpp │ │ ├── for_em_map.cpp │ │ ├── lazy_propagation.cpp │ │ ├── leitura_pair.cpp │ │ ├── map.cpp │ │ ├── ordenar_vetor_crescente.cpp │ │ ├── ordenar_vetor_decrescente.cpp │ │ ├── pilha.cpp │ │ ├── set.cpp │ │ ├── sort_em_structs.cpp │ │ ├── union-find-pd-tamanho-conjunto.cpp │ │ ├── union-find-pd.cpp │ │ ├── utilizando_pair_de_pair.cpp │ │ └── verifica_se_elemento_existe_vector.cpp │ ├── grafos │ │ ├── bfs.cpp │ │ ├── caminho_euleniano.cpp │ │ ├── dfs.cpp │ │ ├── dijkstra.cpp │ │ ├── dijkstra_matriz.cpp │ │ ├── floyd_warshall.cpp │ │ ├── grafo_bipartido.cpp │ │ ├── kruskal_agm.cpp │ │ ├── lca.cpp │ │ ├── lista_adjacencia.cpp │ │ ├── lista_de_arestas.cpp │ │ ├── matriz_adjacencia.cpp │ │ ├── ordenacao_topologica.cpp │ │ └── prim_agm.cpp │ ├── matematica_computacional │ │ ├── a_pow_b_mod_p.cpp │ │ ├── ab_mod_p.cpp │ │ ├── adc_notacao_cient.cpp │ │ ├── and_nos_bits.cpp │ │ ├── arrendondamento_cima.cpp │ │ ├── casas_decimais_fixas.cpp │ │ ├── check_bit_is_set.cpp │ │ ├── check_is_power_2.cpp │ │ ├── clear_bit.cpp │ │ ├── comparacao_double.cpp │ │ ├── condicao_existencia_triangulo.cpp │ │ ├── contar_bits_iguais_1.cpp │ │ ├── conversao_int_decimal.cpp │ │ ├── crivo_erastotenes.cpp │ │ ├── desliga_bit.cpp │ │ ├── digital-root-x.cpp │ │ ├── div_float_double.cpp │ │ ├── div_numeros_inteiros_resto_negativo.cpp │ │ ├── fatorizacao_primos.cpp │ │ ├── geometria_computacional_basica │ │ │ ├── area_do_poligono.cpp │ │ │ ├── ccw.cpp │ │ │ ├── comparacao_fracoes.cpp │ │ │ ├── distancia_entre_dois_pontos.cpp │ │ │ ├── distancia_entre_dois_pontos_complex.cpp │ │ │ ├── distancia_entre_ponto_e_reta.cpp │ │ │ ├── ponto_e_vetor_1.cpp │ │ │ ├── ponto_e_vetor_2.cpp │ │ │ ├── ponto_e_vetor_complex.cpp │ │ │ ├── produto_escalar.cpp │ │ │ ├── produto_escalar_complex.cpp │ │ │ ├── produto_vetorial.cpp │ │ │ └── produto_vetorial_complex.cpp │ │ ├── get_lsb.cpp │ │ ├── k-esimo-digital-root-igual-a-x.cpp │ │ ├── liga_bit_em_numero.cpp │ │ ├── maior_dc.cpp │ │ ├── maior_divisor_comum_GCD.cpp │ │ ├── max_entre_dois_num.cpp │ │ ├── menor_dc.cpp │ │ ├── menor_divisor_comum_LCM.cpp │ │ ├── min_entre_dois_num.cpp │ │ ├── mmc.cpp │ │ ├── modulo_2i_bitwise.cpp │ │ ├── n_fatorial_mod_p.cpp │ │ ├── n_mod_p.cpp │ │ ├── num_casas_decimais_num.cpp │ │ ├── num_combi_conj.cpp │ │ ├── num_permutacoes_conj.cpp │ │ ├── or_nos_bits.cpp │ │ ├── primo_rapido_sqrt_n.cpp │ │ ├── set_bit.cpp │ │ ├── shift_dir.cpp │ │ ├── shift_esq.cpp │ │ ├── tricks_cmath.cpp │ │ ├── xor_nos_bits.cpp │ │ ├── zera_conteudo_array_1d.cpp │ │ └── zera_conteudo_array_2d.cpp │ ├── outros │ │ ├── busca_binaria.cpp │ │ ├── formas_escrever_tipos_dados.cpp │ │ ├── geraPossibilidadesLetras.cpp │ │ ├── gerar_numeros_aleatorios.cpp │ │ ├── inicializar_vetor_com_valor_predefinido.cpp │ │ ├── operacoes_para_modificar_sequencias.cpp │ │ └── permutacoes.cpp │ ├── programacao_dinamica │ │ ├── CalculadoraQuebradaUsandoPD.java │ │ ├── contagem_inversoes.cpp │ │ ├── corte_haste.c │ │ ├── fibonnaci.cpp │ │ ├── formas-troco.cpp │ │ ├── formigaNoTetraedo.cpp │ │ ├── maior_subsequencia_comum.cpp │ │ ├── maior_subsequencia_comum_2.cpp │ │ ├── maior_subsequencia_crescente.cpp │ │ ├── minimo_moedas_troco.cpp │ │ ├── mochila-recursiva.cpp │ │ ├── mochila.c │ │ ├── soma_maxima_intervalo.cpp │ │ ├── troco_eh_possivel.cpp │ │ └── vertex_cover.cpp │ ├── strings │ │ ├── busca.cpp │ │ ├── conversoes │ │ │ ├── caractere_maiusculo.cpp │ │ │ ├── caractere_minusculo.cpp │ │ │ ├── char_para_int.cpp │ │ │ ├── int_para_string.cpp │ │ │ ├── string_para_int.cpp │ │ │ ├── string_para_long_long.cpp │ │ │ ├── string_para_unsigned_int.cpp │ │ │ └── string_para_unsigned_long_long.cpp │ │ ├── insert_erase_replace.cpp │ │ ├── modificacoes │ │ │ ├── apagar_intervalo_string.cpp │ │ │ ├── dividir_string_por_token.cpp │ │ │ ├── inverter_string.cpp │ │ │ ├── remover_caractere_toda_string.cpp │ │ │ └── substring.cpp │ │ ├── streamstream_conversao_string.cpp │ │ ├── string_streams.cpp │ │ ├── uppercase_cout.cpp │ │ └── verificacoes │ │ │ ├── verifica_caractere_intervalo_A_z.cpp │ │ │ └── verifica_string_vazia.cpp │ └── template.cpp ├── figures │ ├── estruturas │ │ └── arvore_de_segmentos.png │ ├── grafos │ │ ├── LCA.png │ │ ├── OT.png │ │ ├── agm.png │ │ ├── grafos_bipartidos.png │ │ ├── representacao_lista_adj.png │ │ └── representacao_matriz_adj.png │ ├── logo_icpc_mdp.png │ ├── logo_if_horizontal.jpg │ ├── matematica_computacional │ │ ├── Condicao_existencia_triangulo.png │ │ ├── geometria_basica │ │ │ ├── distancia_entre_dois_pontos_1.png │ │ │ ├── distancia_entre_dois_pontos_2.png │ │ │ ├── equacao_circulo.png │ │ │ ├── equacao_reta.png │ │ │ ├── teorema_tales_1.png │ │ │ └── teorema_tales_2.png │ │ └── geometria_computacional_basica │ │ │ ├── produto_escalar.png │ │ │ └── produto_vetorial.png │ └── outros │ │ ├── Ascii_Table.png │ │ ├── cpp_limits.png │ │ └── eds_c++.png ├── main.tex └── maratona_template.sty ├── Notebook_Maratonas_v1.3.pdf ├── README.md └── Upsolving ├── A2-Online-Judge └── 1-Under-1300 │ ├── 110A.cpp │ ├── 218B.cpp │ ├── 263A.cpp │ ├── 266A.cpp │ ├── 266B.cpp │ ├── 271A.cpp │ ├── 275A.cpp │ ├── 277B.cpp │ ├── 281A.cpp │ ├── 282A.cpp │ ├── 32B.cpp │ ├── 59A.cpp │ ├── 61A.cpp │ ├── 69A.cpp │ ├── 71A.cpp │ └── 80A.cpp ├── Codeforces ├── 1077A.cpp ├── 1092A.cpp ├── 1092B.cpp ├── 1107A.cpp ├── 1107B.cpp ├── 1107C.cpp ├── 1144A.cpp ├── 1144B.cpp └── 1144C.cpp ├── NEPS Academy ├── Estruturas de Dados │ ├── Fila │ │ └── Copa_Do_Mundo.cpp │ ├── Pair │ │ ├── pair_A_times.cpp │ │ └── pair_B_sorvete.cpp │ ├── Pilha │ │ └── expressoes.cpp │ ├── Set │ │ ├── frequencia_na_aula.cpp │ │ ├── tacos_de_bilhar.cpp │ │ └── troca_de_cartas.cpp │ ├── Union Find │ │ ├── fusoes.cpp │ │ ├── guildas.cpp │ │ ├── union-find-pd-tamanho-conjunto.cpp │ │ └── union-find-pd.cpp │ └── Vector │ │ ├── vector_A_boraBora.cpp │ │ └── vector_A_fila.cpp ├── Grafos │ ├── flood_fill.cpp │ ├── inputf.in │ ├── mobile.cpp │ └── outputf.in └── Programação Básica │ ├── funcoes_recursivas_A.cpp │ ├── funcoes_recursivas_E.cpp │ ├── inputf.in │ └── outputf.in ├── SPOJ └── backpack.cpp └── URI ├── 1022.cpp ├── 1023.cpp ├── 1025.cpp ├── 1026.cpp ├── 1034.cpp ├── 1059.cpp ├── 1060.cpp ├── 1062.cpp ├── 1065.cpp ├── 1077.cpp ├── 1148-2.cpp ├── 1148.cpp ├── 1152.cpp ├── 1153.cpp ├── 1162.cpp ├── 1164.cpp ├── 1169.cpp ├── 1193.cpp ├── 1197.cpp ├── 1199.cpp ├── 1212.cpp ├── 1214.cpp ├── 1235.cpp ├── 1238.cpp ├── 1240.cpp ├── 1241.cpp ├── 1244.cpp ├── 1247.cpp ├── 1249.cpp ├── 1256.cpp ├── 1257.cpp ├── 1259.cpp ├── 1272.cpp ├── 1273.cpp ├── 1281.cpp ├── 1323.cpp ├── 1340.cpp ├── 1429.cpp ├── 1436.cpp ├── 1534.cpp ├── 1541.cpp ├── 1548.cpp ├── 1557.cpp ├── 1566.cpp ├── 1789.cpp ├── 1795.cpp ├── 1804.cpp ├── 1805.cpp ├── 1827.cpp ├── 1828.cpp ├── 1837.cpp ├── 1847.cpp ├── 1848.cpp ├── 1858.cpp ├── 1864.cpp ├── 1865.cpp ├── 1871.cpp ├── 1893.cpp ├── 1914.cpp ├── 1921.cpp ├── 1929.cpp ├── 1930.cpp ├── 1933.cpp ├── 1957.cpp ├── 1958.cpp ├── 1959.cpp ├── 1960.cpp ├── 1961.cpp ├── 1962.cpp ├── 1963.cpp ├── 1973.cpp ├── 1983.cpp ├── 1984.cpp ├── 2003.cpp ├── 2006.cpp ├── 2023.cpp ├── 2025.cpp ├── 2028.cpp ├── 2029.cpp ├── 2031.cpp ├── 2057.cpp ├── 2059.cpp ├── 2061.cpp ├── 2062.cpp ├── 2126.cpp ├── 2137.cpp ├── 2139.cpp ├── 2140.cpp ├── 2150.cpp ├── 2153.cpp ├── 2162.cpp ├── 2165.cpp ├── 2166.cpp ├── 2167.cpp ├── 2168.cpp ├── 2172.cpp ├── 2176.cpp ├── 2203.cpp ├── 2221.cpp ├── 2222.cpp ├── 2234.cpp ├── 2235.cpp ├── 2242.cpp ├── 2310.cpp ├── 2311.cpp ├── 2313.cpp ├── 2334.cpp ├── 2338.cpp ├── 2484.cpp ├── 2486.cpp ├── 2493.cpp ├── 2510.cpp ├── 2520.cpp ├── 2523.cpp ├── 2533.cpp ├── 2534.cpp ├── 2538.cpp ├── 2540.cpp ├── 2542.cpp ├── 2543.cpp ├── 2544.cpp ├── 2547.cpp ├── 2551.cpp ├── 2590.cpp ├── 2633.cpp ├── 2661.cpp ├── 2717.cpp ├── 2718.cpp ├── 2747.cpp ├── 2749.cpp ├── 2763.cpp ├── 2788.cpp └── 2855.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | **/input.txt 2 | **/input.in* 3 | **/in.txt* 4 | **/in 5 | **/out 6 | **/output.txt 7 | **/out.out 8 | **/out.in 9 | **/output.in 10 | Outros/ 11 | 12 | **/*.exe 13 | 14 | uri/2788\.cpp 15 | 16 | aquecimentoOLIP2019/\.vscode/ 17 | 18 | maratonaInatel2019/\.vscode/ 19 | 20 | *.txt 21 | -------------------------------------------------------------------------------- /Contests/Aquecimento da OBI - Fase Nacional 2018/Primo.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class Primo { 4 | 5 | public static void main(String a[]) { 6 | ArrayList primos = new ArrayList(); 7 | 8 | for(int i = 0; i < 1000000; ++i) { 9 | primos.add(0); 10 | } 11 | primos.set(0,1); 12 | primos.set(1,1); 13 | for(int i = 0; i < 1000000; ++i) { 14 | for(int j = i; j < 1000000; ++j) { 15 | primos.set(i*j,1); 16 | } 17 | } 18 | 19 | for(int i = 0; i < 1000000; ++i) { 20 | System.out.println(primos.get(i)); 21 | } 22 | 23 | 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /Contests/Codeforces/div2/573/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define MOD 1000000007 4 | #define INF 0x3f3f3f3f 5 | #define INFLL 0x3f3f3f3f3f3f3f3f 6 | #define EPS 1e-9 7 | #define PI 3.141592653589793238462643383279502884 8 | #define pb push_back 9 | #define pf push_front 10 | #define fi first 11 | #define se second 12 | #define mp make_pair 13 | #define sz (x) int(x.size()) 14 | #define all (x) x.begin(), x.end() 15 | #define mset (x, y) memset(&x, (y), sizeof(x)) 16 | 17 | using namespace std; 18 | 19 | typedef long long ll; 20 | typedef unsigned long long ull; 21 | typedef long double ld; 22 | typedef unsigned int uint; 23 | typedef vector vi; 24 | typedef pair ii; 25 | 26 | int main(){ 27 | //ios::sync_with_stdio(false);cin.tie(NULL); 28 | 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Contests/Codeforces/educational/68-1194-div2/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define MOD 1000000007 4 | #define INF 0x3f3f3f3f 5 | #define INFLL 0x3f3f3f3f3f3f3f3f 6 | #define EPS 1e-9 7 | #define PI 3.141592653589793238462643383279502884 8 | #define pb push_back 9 | #define pf push_front 10 | #define fi first 11 | #define se second 12 | #define mp make_pair 13 | #define sz (x) int(x.size()) 14 | #define all (x) x.begin(), x.end() 15 | #define mset (x, y) memset(&x, (y), sizeof(x)) 16 | 17 | using namespace std; 18 | 19 | typedef long long ll; 20 | typedef unsigned long long ull; 21 | typedef long double ld; 22 | typedef unsigned int uint; 23 | typedef vector vi; 24 | typedef pair ii; 25 | 26 | int main(){ 27 | int t; 28 | ll n, x; 29 | 30 | scanf("%d", &t); 31 | 32 | for(int i = 0; i < t; i++){ 33 | scanf("%ld %ld", &n, &x); 34 | 35 | printf("%d\n", (x*2)); 36 | } 37 | 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Contests/Codeforces/educational/68-1194-div2/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define MOD 1000000007 4 | #define INF 0x3f3f3f3f 5 | #define INFLL 0x3f3f3f3f3f3f3f3f 6 | #define EPS 1e-9 7 | #define PI 3.141592653589793238462643383279502884 8 | #define pb push_back 9 | #define pf push_front 10 | #define fi first 11 | #define se second 12 | #define mp make_pair 13 | #define sz (x) int(x.size()) 14 | #define all (x) x.begin(), x.end() 15 | #define mset (x, y) memset(&x, (y), sizeof(x)) 16 | 17 | using namespace std; 18 | 19 | typedef long long ll; 20 | typedef unsigned long long ull; 21 | typedef long double ld; 22 | typedef unsigned int uint; 23 | typedef vector vi; 24 | typedef pair ii; 25 | 26 | int main(){ 27 | 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Contests/Codeforces/gym/247576/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | 8 | scanf("%d ", &n); 9 | 10 | string numero; 11 | 12 | for(int i = 0; i < n; i++){ 13 | cin >> numero; 14 | 15 | vector vetorChar(numero.begin(), numero.end()); 16 | sort(vetorChar.begin(), vetorChar.end()); 17 | int contadorZeros = 0; 18 | for(const char &c: vetorChar){ 19 | if(c == '0'){ 20 | contadorZeros++; 21 | }else if(c != '0' && contadorZeros > 0){ 22 | cout << c; 23 | while(contadorZeros-- != 0) 24 | cout << '0'; 25 | }else{ 26 | cout << c; 27 | } 28 | 29 | } 30 | cout << "\n"; 31 | 32 | } 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Contests/Codeforces/gym/247576/c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | 8 | scanf("%d ", &n); 9 | 10 | string cartas; 11 | bool q, j, k, a; 12 | 13 | for(int i = 0; i < n; i++){ 14 | cin >> cartas; 15 | q = j = k = a = false; 16 | 17 | for(int z = 0; z < (int)cartas.length(); z++){ 18 | if(q & j & k & a) break; 19 | if(cartas[z] == 'Q') 20 | q = true; 21 | else if(cartas[z] == 'J') 22 | j = true; 23 | else if(cartas[z] == 'K') 24 | k = true; 25 | else if(cartas[z] == 'A') 26 | a = true; 27 | } 28 | if(q & j & k & a){ 29 | printf("Aaah muleke\n"); 30 | }else{ 31 | printf("Ooo raca viu\n"); 32 | } 33 | } 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Contests/Codeforces/gym/247576/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | 8 | scanf("%d ", &n); 9 | 10 | string cartas; 11 | bool q, j, k, a; 12 | 13 | for(int i = 0; i < n; i++){ 14 | cin >> cartas; 15 | q = j = k = a = false; 16 | 17 | for(int z = 0; z < (int)cartas.length(); z++){ 18 | if(q & j & k & a) break; 19 | if(cartas[z] == 'Q' && !q) 20 | q = true; 21 | else if(cartas[z] == 'J' & q) 22 | j = true; 23 | else if(cartas[z] == 'K' & q & j) 24 | k = true; 25 | else if(cartas[z] == 'A' & q & j & k) 26 | a = true; 27 | } 28 | if(q & j & k & a){ 29 | printf("Agora vai\n"); 30 | }else{ 31 | printf("Agora apertou sem abracar\n"); 32 | } 33 | } 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Contests/Codeforces/gym/247576/f.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | 7 | struct Ponto 8 | { 9 | double x; 10 | double y; 11 | 12 | double distancia(Ponto p){ 13 | double ans; 14 | ans = ((p.x-x)*(p.x-x)) + ((p.y-y)*(p.y-y)); 15 | return sqrt(ans); 16 | } 17 | }pontos[3]; 18 | 19 | int main(){ 20 | double a, b, c, p, ans; 21 | int n; 22 | 23 | scanf("%d", &n); 24 | 25 | for(int i = 0; i < n; i++){ 26 | for(int j = 0; j < 3; j++){ 27 | scanf("%lf %lf", &pontos[j].x, &pontos[j].y); 28 | } 29 | a = pontos[0].distancia(pontos[1]); 30 | b = pontos[1].distancia(pontos[2]); 31 | c = pontos[2].distancia(pontos[0]); 32 | p = (a+b+c)/2.0; 33 | ans = sqrt(p*(p-a)*(p-b)*(p-c)); 34 | 35 | printf("%.3lf\n", ans); 36 | } 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Contests/Codeforces/gym/247576/g.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | 7 | int main(){ 8 | int n; 9 | ll PB, PM; 10 | PB = PM = 0; 11 | 12 | scanf("%d", &n); 13 | 14 | int cesta[n]; 15 | 16 | for(int i = 0; i < n; i++){ 17 | scanf("%d", &cesta[i]); 18 | } 19 | 20 | int i, j; 21 | PB = cesta[0]; 22 | PM = cesta[n-1]; 23 | i = 1; 24 | j = n-2; 25 | ll maior = 0; 26 | 27 | if(n == 1){ 28 | printf("0\n"); 29 | 30 | return 0; 31 | } 32 | 33 | while(i < j){ 34 | if(PB == PM) 35 | maior = PB; 36 | if(PB < PM){ 37 | PB += cesta[i++]; 38 | }else{ 39 | PM += cesta[j--]; 40 | } 41 | } 42 | 43 | if(PB == PM){ 44 | maior = PB; 45 | } 46 | 47 | printf("%lld\n", maior); 48 | 49 | return 0; 50 | } -------------------------------------------------------------------------------- /Contests/Codeforces/gym/247576/h(Ygor).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | char s[1005]; 6 | int dp[1005][1005]; 7 | 8 | string S; 9 | 10 | int solve(int i, int j){ 11 | if(i > j) return 0; 12 | 13 | if(i == j) return s[i] != 'a'; 14 | 15 | if(dp[i][j] != -1) return dp[i][j]; 16 | 17 | if(s[i] == 'a' || s[j] == 'a') return solve(i + (s[i] == 'a'), j - (s[j] == 'a')); 18 | 19 | if(s[i] == s[j]) return 2 + solve(i+1, j-1); 20 | 21 | return dp[i][j] = max(solve(i+1, j), solve(i, j-1)); 22 | 23 | } 24 | 25 | int main(){ 26 | scanf("%s", s); 27 | 28 | memset(dp, -1, sizeof dp); 29 | 30 | printf("%d\n", solve(0, strlen(s)-1)); 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Contests/Codeforces/gym/247576/h.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int LPS(string X, int i, int j, auto &lookup) 6 | { 7 | if (i > j) 8 | return 0; 9 | 10 | if (i == j) 11 | return 1; 12 | 13 | string key = to_string(i) + "|" + to_string(j); 14 | 15 | if (lookup.find(key) == lookup.end()) 16 | { 17 | if (X[i] == X[j]) 18 | lookup[key] = LPS(X, i + 1, j - 1, lookup) + 2; 19 | else 20 | 21 | lookup[key] = max (LPS(X, i, j - 1, lookup), 22 | LPS(X, i + 1, j, lookup)); 23 | } 24 | 25 | return lookup[key]; 26 | } 27 | 28 | 29 | int main(){ 30 | int N; 31 | string palavra; 32 | 33 | cin >> palavra; 34 | 35 | N = (int)palavra.length(); 36 | 37 | palavra.erase(remove(palavra.begin(), palavra.end(), 'a'), palavra.end()); 38 | 39 | if(palavra.length() == 0){ 40 | cout << "0\n"; 41 | }else{ 42 | unordered_map lookup; 43 | 44 | cout << LPS(palavra, 0, N, lookup) << endl; 45 | } 46 | 47 | 48 | 49 | return 0; 50 | } -------------------------------------------------------------------------------- /Contests/Codeforces/gym/247576/j(Ygor).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | char aux[30]; 6 | int dp[15][30][2], t; 7 | 8 | int solve(int pos, int seteum, int prefix){ 9 | 10 | if(pos == t) return seteum; 11 | 12 | if(dp[pos][seteum][prefix] != -1) return dp[pos][seteum][prefix]; 13 | 14 | int d = prefix ? aux[pos] - '0' : 9; 15 | 16 | int ans = 0; 17 | 18 | for(int i=0;i<=d;i++){ 19 | ans+=solve(pos+1, seteum + ((i == 7) || (i == 1)), prefix & (i == d)); 20 | } 21 | 22 | return dp[pos][seteum][prefix] = ans; 23 | 24 | } 25 | 26 | int main(){ 27 | 28 | long long n; 29 | scanf("%I64d", &n); 30 | sprintf(aux, "%I64d", n); 31 | t = strlen(aux); 32 | memset(dp, -1, sizeof dp); 33 | printf("%d\n", solve(0, 0, 1)); 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Contests/Codeforces/gym/247576/k.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long a, b, res; 7 | 8 | scanf("%lld %lld", &a, &b); 9 | 10 | res = a%b; 11 | 12 | printf("%lld", res); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Contests/Codeforces/gym/247576/l.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | 7 | ll mod(string a, int b) 8 | { 9 | ll ans = 0; 10 | 11 | for (int i = 0; i < a.length(); i++) 12 | ans = (ans*10 + (ll)a[i] - '0') % b; 13 | 14 | return ans; 15 | } 16 | 17 | int main(){ 18 | ll b, ans; 19 | string a; 20 | 21 | cin >> a; 22 | 23 | scanf(" %lld", &b); 24 | 25 | ans = mod(a, b); 26 | 27 | printf("%lld\n", ans); 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Contests/Contest Made by Woman URI/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int n; 16 | 17 | cin >> n; 18 | 19 | cin.ignore(); 20 | 21 | forn(i, n){ 22 | vector lista; 23 | string line; 24 | 25 | getline(cin, line); 26 | 27 | stringstream ss; 28 | 29 | ss << line; 30 | 31 | while(ss >> line){ 32 | lista.push_back(line); 33 | } 34 | 35 | sort( lista.begin(), lista.end() ); 36 | lista.erase( unique( lista.begin(), lista.end() ), lista.end() ); 37 | 38 | forn(i, lista.size()){ 39 | if(i != lista.size()-1) 40 | cout << lista[i] << " "; 41 | else 42 | cout << lista[i] << endl; 43 | } 44 | } 45 | 46 | 47 | 48 | return 0; 49 | } -------------------------------------------------------------------------------- /Contests/Contest Made by Woman URI/E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | 15 | typedef pair ii; 16 | 17 | void dijkstra( const vector< vector >& g, int v, vector& dist ) { 18 | int d, cost, w; set Q; 19 | dist[v] = 0; Q.insert( ii(0, v) ); 20 | while( !Q.empty() ) { 21 | ii top = *Q.begin(); 22 | Q.erase( Q.begin() ); v = top.second; d = top.first; 23 | forn(i,g[v].sz) { 24 | w = g[v][i].second; cost = g[v][i].first; 25 | if ( dist[v] + cost < dist[w] ) { 26 | if ( dist[w] != INF ) 27 | Q.erase( Q.find( ii( dist[w], w ) ) ); 28 | dist[w] = dist[v] + cost; Q.insert( ii( dist[w], w ) ); 29 | } 30 | } 31 | } 32 | } 33 | 34 | int main(){ 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Contests/Contest Made by Woman URI/F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Contests/Contest Made by Woman URI/G.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int n; 16 | 17 | while(cin >> n){ 18 | list livros; 19 | int contador = 0, atual; 20 | 21 | forn(i, n){ 22 | cin >> atual; 23 | if(find(livros.begin(), livros.end(), atual) != livros.end()) 24 | continue; 25 | if(livros.size() != 4){ 26 | livros.push_back(atual); 27 | contador++; 28 | }else if(find(livros.begin(), livros.end(), atual) == livros.end()){ 29 | livros.pop_front(); 30 | livros.push_back(atual); 31 | contador++; 32 | } 33 | } 34 | cout << contador << endl; 35 | } 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Contests/Contest Natal URI 2018/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int i; 7 | 8 | scanf("%d", &i); 9 | 10 | printf("Ent"); 11 | for(int j = 0; j < i; j++){ 12 | printf("a"); 13 | } 14 | printf("o eh N"); 15 | for(int j = 0; j < i; j++){ 16 | printf("a"); 17 | } 18 | printf("t"); 19 | for(int j = 0; j < i; j++){ 20 | printf("a"); 21 | } 22 | printf("l!\n"); 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Contests/Contest Natal URI 2018/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int a, c, x, y; 7 | int res; 8 | bool maior; 9 | 10 | scanf("%d %d %d %d", &a, &c, &x, &y); 11 | 12 | res = c - a - x- y; 13 | maior = x > (y/2); 14 | 15 | if(res > 0){ 16 | printf("Igor feliz!\n"); 17 | }else if(maior){ 18 | printf("Caio, a culpa eh sua!\n"); 19 | }else{ 20 | printf("Igor bolado!\n"); 21 | } 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Contests/Contest Natal URI 2018/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | int contador; 8 | int pulos; 9 | string gelo; 10 | 11 | scanf("%d ", &n); 12 | 13 | contador = pulos = 0; 14 | for(int i = 0; i < n; i++){ 15 | getline(cin, gelo); 16 | if(gelo[0] == '.'){ 17 | contador++; 18 | if(contador == 3){ 19 | printf("N\n"); 20 | return 0; 21 | } 22 | }else{ 23 | if(contador > 0){ 24 | pulos++; 25 | } 26 | contador = 0; 27 | } 28 | } 29 | if(contador > 0){ 30 | pulos++; 31 | } 32 | 33 | printf("%d\n", pulos); 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Contests/Contest Natal URI 2018/E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int e, d; 7 | 8 | scanf("%d %d", &e, &d); 9 | 10 | if(e > d){ 11 | printf("Eu odeio a professora!\n"); 12 | }else if(e <= (d-3)){ 13 | printf("Muito bem! Apresenta antes do Natal!\n"); 14 | }else{ 15 | printf("Parece o trabalho do meu filho!\n"); 16 | e+=2; 17 | if(e < 24){ 18 | printf("TCC Apresentado!\n"); 19 | }else{ 20 | printf("Fail! Entao eh nataaaaal!\n"); 21 | } 22 | } 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Contests/Final Nacional da XXIII Maratona SBC de Programação 2018/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int degree, degree_1, degree_2; 7 | 8 | scanf("%d.%d", °ree_1, °ree_2); 9 | 10 | degree = (degree_1*100)+degree_2; 11 | 12 | int res = ((degree*36000)/__gcd(36000, degree)); 13 | res/=degree; 14 | printf("%d\n", res); 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Contests/Final Nacional da XXIII Maratona SBC de Programação 2018/L.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | // primos = 0, não primos = 1 6 | int primos[100001]; 7 | 8 | void crivo(int n); 9 | 10 | int main() { 11 | int q, n, k, contador; 12 | 13 | scanf("%d", &q); 14 | 15 | while(q--){ 16 | scanf("%d %d", &n, &k); 17 | memset(primos, 0, sizeof(primos)); 18 | 19 | if(k > n){ 20 | printf("%d\n", (n-1)); 21 | }else{ 22 | crivo(n); 23 | 24 | contador = 0; 25 | for(int i = 2; i <= n; i++){ 26 | if(primos[i] == 1 || i <= k){ 27 | contador++; 28 | } 29 | if(!primos[i]){ 30 | for(int j = 2; i*j <= n; j++){ 31 | primos[i*j] = 0; 32 | } 33 | } 34 | } 35 | printf("%d\n", contador); 36 | } 37 | 38 | } 39 | return 0; 40 | } 41 | 42 | void crivo(int n) { 43 | int raiz = sqrt(n); 44 | 45 | for (int i = 2; i <= raiz; ++i) { 46 | if (!primos[i]) { 47 | for (int j = 2; j*i <= n; ++j) { 48 | primos[i*j] = 1; 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Contests/GEOLIP - 2/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | double x, y; 7 | 8 | scanf("%lf %lf", &x, &y); 9 | 10 | printf("%.3lf km/l\n", (x/y)); 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /Contests/GEOLIP - 2/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | int j1, j2; 8 | int pj1, pj2; 9 | 10 | while(true){ 11 | scanf("%d", &n); 12 | if(n == 0) break; 13 | pj1 = pj2 = 0; 14 | for(int i = 0; i < n; i++){ 15 | scanf("%d %d", &j1, &j2); 16 | if(j1 > j2){ 17 | pj1++; 18 | }else if(j2 > j1){ 19 | pj2++; 20 | } 21 | } 22 | printf("%d %d\n", pj1, pj2); 23 | 24 | } 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Contests/GEOLIP - 2/c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int c; 7 | 8 | scanf("%d", &c); 9 | 10 | while(c--){ 11 | int n; 12 | scanf("%d ", &n); 13 | vector pessoas; 14 | string aux; 15 | int diff = 0; 16 | for(int i = 0; i < n; i++){ 17 | cin >> aux; 18 | pessoas.push_back(aux); 19 | } 20 | for(int i = 0; i < pessoas.size(); i++){ 21 | for(int j = 0; j < pessoas.size(); j++){ 22 | if(j == i) continue; 23 | if(pessoas.at(i) != pessoas.at(j)){ 24 | diff = 1; 25 | break; 26 | } 27 | } 28 | } 29 | if(diff){ 30 | printf("ingles\n"); 31 | }else{ 32 | cout << pessoas.at(0) << "\n"; 33 | } 34 | char c; 35 | scanf("%c", &c); 36 | } 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Contests/GEOLIP - 2/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int v1[5], v2[5]; 7 | 8 | int ok = 1; 9 | 10 | for(int i = 0; i < 5; i++){ 11 | scanf("%d", &v1[i]); 12 | } 13 | for(int i = 0; i < 5; i++){ 14 | scanf("%d", &v2[i]); 15 | } 16 | for(int i = 0; i < 5; i++){ 17 | if(v1[i] == v2[i]){ 18 | ok = 0; 19 | break; 20 | } 21 | } 22 | 23 | if(ok){ 24 | printf("Y\n"); 25 | }else{ 26 | printf("N\n"); 27 | } 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Contests/GEOLIP - 2/e.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | 8 | scanf("%d ", &n); 9 | 10 | string s; 11 | 12 | while(n--){ 13 | cin >> s; 14 | } 15 | 16 | printf("Ciencia da Computacao\n"); 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Contests/GEOLIP - 2/f.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | double volume, diametro; 7 | double pi = 3.14; 8 | while(scanf("%lf %lf", &volume, &diametro) != EOF){ 9 | double raio, altura, area; 10 | 11 | raio = diametro/2; 12 | 13 | altura = volume/(pi*pow(raio, 2.0)); 14 | area = pi*raio*raio; 15 | 16 | cout << fixed << setprecision(2); 17 | cout << "ALTURA = " << altura << endl; 18 | cout << "AREA = " << area << endl; 19 | 20 | //printf("ALTURA = %.2lf\nAREA = %.2lf\n", altura, area); 21 | } 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Contests/GEOLIP - 2/h.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string s; 7 | 8 | getline(cin, s); 9 | 10 | if(s.length() <= 140){ 11 | printf("TWEET\n"); 12 | }else{ 13 | printf("MUTE\n"); 14 | } 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Contests/GEOLIP - 2/i.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | 8 | scanf("%d", &n); 9 | 10 | int anterior, atual; 11 | int aconteceu = 0; 12 | 13 | for(int i = 0; i < n; i++){ 14 | scanf("%d", &atual); 15 | if(i > 0){ 16 | if(atual < anterior){ 17 | printf("%d\n", i+1); 18 | aconteceu = 1; 19 | break; 20 | } 21 | } 22 | anterior = atual; 23 | } 24 | 25 | if(!aconteceu){ 26 | printf("0\n"); 27 | } 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Contests/GEOLIP - 2/j.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | char lixo; 8 | string lingua, crianca, traducao; 9 | map feliz_natal; 10 | 11 | scanf("%d ", &n); 12 | 13 | while(n--){ 14 | getline(cin, lingua); 15 | getline(cin, traducao); 16 | 17 | feliz_natal[lingua] = traducao; 18 | } 19 | 20 | scanf(" %d ", &n); 21 | 22 | int inicio = 1; 23 | 24 | while(n--){ 25 | if(inicio){ 26 | inicio = 0; 27 | }else{ 28 | printf("\n"); 29 | } 30 | getline(cin, crianca); 31 | getline(cin, lingua); 32 | 33 | cout << crianca << "\n"; 34 | cout << feliz_natal[lingua] << "\n"; 35 | } 36 | 37 | cout << endl; 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Contests/GEOLIP - 2/k.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | 8 | while(scanf("%d", &n) != EOF){ 9 | set vetor; 10 | int a; 11 | 12 | for(int i = 0; i < n; i++){ 13 | scanf("%d", &a); 14 | vetor.insert(a); 15 | } 16 | 17 | printf("%d\n", vetor.size()-2); 18 | } 19 | 20 | 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Contests/GEOLIP - 2/l.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | 8 | scanf("%d", &n); 9 | 10 | while(n--){ 11 | int p; 12 | char lixo; 13 | string pa, c; 14 | vector coisas; 15 | 16 | scanf("%d ", &p); 17 | 18 | for(int i = 0; i < p; i++){ 19 | cin >> pa >> c; 20 | cout << pa << c << endl; 21 | if(c == "chirrin"){ 22 | coisas.push_back(pa); 23 | }else if(c == "chirrion"){ 24 | for(vector::iterator it = coisas.begin(); it != coisas.end(); ++it){ 25 | if(*it == pa){ 26 | coisas.erase(it); 27 | } 28 | } 29 | } 30 | } 31 | 32 | sort(coisas.begin(), coisas.end()); 33 | 34 | printf("TOTAL\n"); 35 | for(int i = 0; i < coisas.size(); i++){ 36 | cout << coisas.at(i) << "\n"; 37 | } 38 | 39 | scanf("%c", &lixo); 40 | } 41 | 42 | 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Contests/GEOLIP - 2/m.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string s; 7 | 8 | while(cin >> s){ 9 | 10 | } 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /Contests/GEOLIP/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int a, b; 7 | 8 | scanf("%d %d", &a, &b); 9 | 10 | printf("X = %d\n", a+b); 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /Contests/GEOLIP/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | double r, area; 7 | 8 | scanf("%lf", &r); 9 | 10 | area = 3.14159 * r*r; 11 | 12 | printf("A=%.4lf\n", area); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Contests/GEOLIP/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | unsigned long long int a, b; 7 | while(scanf("%llu %llu", &a, &b) != EOF){ 8 | unsigned long long int resultado = a ^ b; 9 | 10 | printf("%llu\n", resultado); 11 | } 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /Contests/GEOLIP/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int gcd(int a, int b) 6 | { 7 | if (b==0) return a; 8 | else return gcd(b, a%b); 9 | } 10 | 11 | int main(){ 12 | int n; 13 | scanf("%d", &n); 14 | for(int i = 0; i < n; i++){ 15 | int a, b; 16 | scanf("%d %d", &a, &b); 17 | 18 | printf("%d\n", gcd(a, b)); 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Contests/GEOLIP/E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int r1, x1, y1, r2, x2, y2; 7 | 8 | while(scanf("%d %d %d %d %d %d", &r1, &x1, &y1, &r2, &x2, &y2) != EOF){ 9 | double dist = sqrt(((x1-x2) * (x1-x2)) + ((y1-y2) * (y1-y2))); 10 | if(dist+r2 <= r1){ 11 | printf("RICO\n"); 12 | }else{ 13 | printf("MORTO\n"); 14 | } 15 | } 16 | 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Contests/GEOLIP/F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | char c; 7 | string n; 8 | while(1){ 9 | cin >> c >> n; 10 | if(c == '0' && n == "0") break; 11 | 12 | n.erase(remove(n.begin(), n.end(), c), n.end()); 13 | 14 | int fim = 0; 15 | for(int i = 0; i < n.length(); i++){ 16 | if(n[i] != '0'){ 17 | break; 18 | } 19 | fim = i-1; 20 | } 21 | n.erase(0, fim); 22 | 23 | if(n == ""){ 24 | cout << "0" << endl; 25 | }else{ 26 | cout << n << endl; 27 | } 28 | 29 | } 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Contests/Maratona Inatel 2019/.vscode/ipch/ba2e4fe17b08f308/KEPARTICIONANDO.ipch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Contests/Maratona Inatel 2019/.vscode/ipch/ba2e4fe17b08f308/KEPARTICIONANDO.ipch -------------------------------------------------------------------------------- /Contests/Maratona Inatel 2019/A(SAMUEL).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int n,m; 6 | char a[105]; 7 | dequevet; 8 | int v; 9 | int main() 10 | { 11 | scanf("%d%d",&n,&m); 12 | int ans; 13 | for(int i = 0 ; i < n ; i++) 14 | { 15 | scanf("%d %s",&v,&a); 16 | vet.push_back(v); 17 | if((i+1) == m) ans = v; 18 | } 19 | 20 | 21 | 22 | while(vet.size() != 1) 23 | { 24 | 25 | if(vet.size() > 1) 26 | { 27 | vet.pop_back(); 28 | 29 | n--; 30 | 31 | } 32 | if(n > 1) 33 | { 34 | vet.pop_front(); 35 | n--; 36 | m--; 37 | } 38 | if(m > n/2 && n > 1) 39 | { 40 | vet.pop_front(); 41 | n--; 42 | m--; 43 | 44 | } 45 | else if(n > 1) 46 | { 47 | 48 | vet.pop_back(); 49 | n--; 50 | 51 | } 52 | 53 | 54 | } 55 | if(vet[0] == ans) printf("SIM\n"); 56 | else printf("NAO\n"); 57 | 58 | 59 | return 0; 60 | } -------------------------------------------------------------------------------- /Contests/Maratona Inatel 2019/e(SAMUEL).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int dp[5005]; 6 | 7 | int n; 8 | 9 | int main() 10 | { 11 | scanf("%d",&n); 12 | int cur = 1; 13 | 14 | while(n--) 15 | { 16 | int op; scanf("%d",&op); 17 | 18 | if(op == 1) 19 | { 20 | int a,b; 21 | scanf("%d%d",&a,&b); 22 | for(int i = 0 ; i <= 5000; i++) 23 | { 24 | 25 | int ans = dp[i]; 26 | if(i >= a) 27 | ans = max(ans, dp[i - a] + b); 28 | 29 | dp[i] = ans; 30 | } 31 | cur++; 32 | } 33 | else 34 | { 35 | int r; scanf("%d",&r); 36 | int aux = cur - 1; 37 | printf("%d\n", dp[r]); 38 | } 39 | } 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Contests/Maratona Inatel 2019/i(SAMUEL).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | unsigned long long n,a,b,aux; 5 | 6 | unsigned long long f(unsigned long long n) 7 | { 8 | return n + (((1 + n)*n)/2); 9 | } 10 | 11 | int main() 12 | { 13 | // cout << f(44720) << endl; 14 | 15 | scanf("%llu",&n); 16 | if(n == 1) 17 | { 18 | printf("0 0\n"); 19 | return 0 ; 20 | } 21 | else if(n == 2) 22 | { 23 | printf("1 0\n"); 24 | return 0; 25 | } 26 | 27 | int k = 1; 28 | a = 0; 29 | b = 0; 30 | n--; 31 | unsigned long long l = 1,r = 1e10; 32 | unsigned long long m,ans; 33 | while(l <= r) 34 | { 35 | 36 | m = l + ((r - l) / 2); 37 | unsigned long long val = f(m); 38 | if(val == n) 39 | { 40 | ans = m; 41 | break; 42 | } 43 | else if(val > n) 44 | { 45 | r = m-1; 46 | ans = m; 47 | } 48 | else 49 | { 50 | 51 | l = m+1; 52 | } 53 | } 54 | 55 | printf("%llu %llu\n",ans , n - ans); 56 | 57 | return 0; 58 | } -------------------------------------------------------------------------------- /Contests/Maratona Inatel 2019/prova.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Contests/Maratona Inatel 2019/prova.pdf -------------------------------------------------------------------------------- /Contests/Maratona Norte 2019/Editorial III MdP do Norte by Dabriel.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Contests/Maratona Norte 2019/Editorial III MdP do Norte by Dabriel.pdf -------------------------------------------------------------------------------- /Contests/Maratona Norte 2019/Prova___III_MdP_do_Norte(1).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Contests/Maratona Norte 2019/Prova___III_MdP_do_Norte(1).pdf -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2018/2862.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n, x; 7 | 8 | scanf("%d", &n); 9 | 10 | while(n--){ 11 | scanf("%d", &x); 12 | 13 | if(x > 8000) 14 | printf("Mais de 8000!\n"); 15 | else 16 | printf("Inseto!\n"); 17 | } 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2018/2863.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n, first; 7 | double t, mt; 8 | 9 | while(scanf("%d", &n) != EOF){ 10 | first = 1; 11 | while(n--){ 12 | scanf("%lf", &t); 13 | if(first){ 14 | first = 0; 15 | mt = t; 16 | }else{ 17 | if(t < mt) 18 | mt = t; 19 | } 20 | } 21 | printf("%.2lf\n", mt); 22 | } 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2018/2864.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | double a,b,c; 8 | double x, res; 9 | 10 | scanf("%d", &n); 11 | 12 | while(n--){ 13 | scanf("%lf %lf %lf", &a, &b, &c); 14 | x = -b/(2*a); 15 | res = a*x*x + b*x + c; 16 | 17 | printf("%.2lf\n", res); 18 | } 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2018/2866.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | string x; 8 | 9 | scanf("%d ", &n); 10 | 11 | while(n--){ 12 | cin >> x; 13 | reverse(x.begin(), x.end()); 14 | for(int i = 0; i < x.length(); ++i){ 15 | if(islower(x[i])){ 16 | cout << x[i]; 17 | } 18 | } 19 | cout << "\n"; 20 | } 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2018/2867.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int c; 7 | 8 | scanf("%d", &c); 9 | 10 | for(int i = 0; i < c; i++){ 11 | int n,m; 12 | scanf("%d %d", &n, &m); 13 | 14 | int resultado = m * log10(n); 15 | resultado++; 16 | printf("%d\n", resultado); 17 | } 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2018/2868.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n, x1,x2, rc, rd, diff; 7 | char op; 8 | 9 | scanf("%d", &n); 10 | 11 | while(n--){ 12 | scanf("%d %c %d = %d", &x1, &op, &x2, &rd); 13 | switch(op){ 14 | case '+': 15 | rc = x1 + x2; 16 | break; 17 | case '-': 18 | rc = x1 - x2; 19 | break; 20 | case 'x': 21 | rc = x1 * x2; 22 | break; 23 | } 24 | diff = abs(rd - rc); 25 | printf("E"); 26 | for(int i = 0; i < diff; i++){ 27 | printf("r"); 28 | } 29 | printf("ou!\n"); 30 | } 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2018/2872.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | bool begin = 1; 7 | string x; 8 | vector pacotes; 9 | 10 | cin.tie(NULL); 11 | cout.sync_with_stdio(false); 12 | 13 | while(cin >> x){ 14 | if(x == "1"){ 15 | if(!begin) 16 | cout << "\n"; 17 | continue; 18 | } 19 | if(x == "0"){ 20 | sort(pacotes.begin(), pacotes.end()); 21 | for(int i = 0; i < pacotes.size(); ++i){ 22 | cout << "Package " << pacotes.at(i) << "\n"; 23 | } 24 | pacotes.clear(); 25 | if(begin) 26 | begin = 0; 27 | continue; 28 | } 29 | cin >> x; 30 | pacotes.push_back(x); 31 | } 32 | cout << "\n"; 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2019/c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | typedef pair ii; 6 | 7 | vector adj[401]; 8 | 9 | bool ehLetra(char s){ 10 | if(tolower(s) >= 'a' && tolower(s) <= 'z'){ 11 | return true; 12 | } 13 | return false; 14 | } 15 | 16 | int main(){ 17 | int n; 18 | 19 | cin >> n; 20 | cin.ignore(); 21 | 22 | while(n--){ 23 | string s; 24 | int maiorIntervalo = 0; 25 | getline(cin, s); 26 | 27 | string busca = ""; 28 | int contadorIntervalo = 0; 29 | for(int i = 0; i < (int)s.length(); i++){ 30 | if(ehLetra(s[i])) { 31 | busca+=tolower(s[i]); 32 | contadorIntervalo++; 33 | }else{ 34 | if(busca == "jogo" || busca == "perdi"){ 35 | if(contadorIntervalo > maiorIntervalo){ 36 | maiorIntervalo = contadorIntervalo; 37 | } 38 | contadorIntervalo = 0; 39 | } 40 | busca=""; 41 | } 42 | } 43 | 44 | cout << maiorIntervalo << "\n"; 45 | } 46 | 47 | return 0; 48 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2019/f.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | double p, t; 7 | 8 | cin >> p >> t; 9 | 10 | double res = (p*t)/2.0000000; 11 | 12 | printf("Concluimos que, dado o limite da entrada, a resposta seria: y = f(x) = %.5lf.\n", res); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2019/g.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | typedef pair ii; 6 | 7 | vector adj[401]; 8 | 9 | int main(){ 10 | int n; 11 | 12 | int acertos[4]; 13 | memset(acertos, 0, sizeof acertos); 14 | 15 | cin >> n; 16 | cin.ignore(); 17 | 18 | while(n--){ 19 | string s, palpites[4], vencedores[4]; 20 | getline(cin, s); 21 | 22 | for(int i = 0 ; i < 4; i++){ 23 | getline(cin, palpites[i]); 24 | } 25 | getline(cin, s); 26 | for(int i = 0; i < 4; i++){ 27 | getline(cin, vencedores[i]); 28 | if(palpites[i] == vencedores[i]){ 29 | acertos[i] = 1; 30 | } 31 | } 32 | } 33 | bool inicio = true; 34 | for(int i = 0; i < 4; i++){ 35 | if(acertos[i] != 1){ 36 | if(inicio){ 37 | cout << (i+1); 38 | inicio = false; 39 | }else{ 40 | cout << " " << (i+1); 41 | } 42 | 43 | } 44 | } 45 | cout << "\n"; 46 | 47 | 48 | return 0; 49 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2019/i.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | 7 | int main(){ 8 | int n, m; 9 | 10 | cin >> n >> m; 11 | cin.ignore(); 12 | 13 | string s; 14 | vector v, d; 15 | for(int i = 0; i < n*m; i++){ 16 | cin >> s; 17 | if(s[1] == 'V'){ 18 | v.push_back(s); 19 | }else{ 20 | d.push_back(s); 21 | } 22 | 23 | } 24 | sort(v.rbegin(), v.rend()); 25 | sort(d.rbegin(), d.rend()); 26 | 27 | for(vector::iterator it = v.begin(); it != v.end(); ++it){ 28 | cout << *it << "\n"; 29 | } 30 | for(vector::iterator it = d.begin(); it != d.end(); ++it){ 31 | cout << *it << "\n"; 32 | } 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2019/solucoes-samuel/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | const int N = 1e5 + 5; 6 | const int mod = 1e9 + 7; 7 | int n; 8 | long long dp[N]; 9 | 10 | long long pd(int x) 11 | { 12 | if(x == 1) return 1; 13 | if(x == 2) return 0; 14 | if(x == 3) return 1; 15 | 16 | if(dp[x] != -1) return dp[x]; 17 | 18 | return dp[x] = (pd(x-2) + pd(x-3))%mod; 19 | } 20 | 21 | int main() 22 | { 23 | memset(dp, -1, sizeof dp); 24 | scanf("%d",&n); 25 | 26 | printf("%lld\n", pd(n)); 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2019/solucoes-samuel/B_junior.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | long long dp[100000], n; 5 | const int M = 1000000007; 6 | 7 | long long pd(int k){ 8 | if(k == n-1) 9 | return 1; 10 | if(k == n-2) 11 | return 0; 12 | if(k == n-3) 13 | return 1; 14 | 15 | if(dp[k] != -1) 16 | return dp[k]; 17 | 18 | long long r = (pd(k+2) + pd(k+3)) % M; 19 | 20 | return dp[k] = r; 21 | 22 | } 23 | 24 | int main(){ 25 | cin>>n; 26 | for(int i=0;i 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | const ll N = 100005,MOD = 1e9 + 7; 7 | 8 | int n; 9 | ll dp[N] = {1,1},sum[3]={0,1,0}; 10 | 11 | int main(){ 12 | scanf("%d",&n); 13 | for(int i=2;i<=n;i++){ 14 | dp[i] = (dp[i]+dp[i-1])%MOD; 15 | dp[i] = (dp[i]+sum[i%3]+1)%MOD; 16 | sum[i%3] = (sum[i%3]+dp[i])%MOD; 17 | } 18 | 19 | int ans; 20 | if(n == 2 || n == 1) ans = n; 21 | else ans = n%3 + 1; 22 | 23 | printf("%lld %d\n",dp[n],ans); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2019/solucoes-samuel/E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | const int N = (int)6; 6 | 7 | int n, m; 8 | int g[N][N]; 9 | 10 | int main() { 11 | scanf("%d %d", &n, &m); 12 | if(n >= 6) { 13 | puts("Festa bunita, festa formosa."); 14 | return 0; 15 | } 16 | for(int i = 0; i < m; ++i) { 17 | int x, y; scanf("%d %d", &x, &y); 18 | x--; y--; 19 | g[x][y] = g[y][x] = 1; 20 | } 21 | bool hasTriangle = false; 22 | for(int i = 0; i < 2; ++i) { 23 | for(int x = 0; x < n; ++x) { 24 | for(int y = 0; y < n; ++y) { 25 | for(int z = 0; z < n; ++z) { 26 | if(x == y || x == z || y == z) continue; 27 | if(g[x][y] == i && g[y][z] == i && g[z][x] == i) hasTriangle = 1; 28 | } 29 | } 30 | } 31 | } 32 | puts(!hasTriangle ? "Role torto." : "Festa bunita, festa formosa."); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2019/solucoes-samuel/F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | double a,b; 8 | 9 | scanf("%lf%lf", &a,&b); 10 | 11 | printf("Concluimos que, dado o limite da entrada, a resposta seria: y = f(x) = %.5lf.\n", (a*b)/2.0); 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2019/solucoes-samuel/H.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int n, d; 6 | char nome[105]; 7 | 8 | mapmp; 9 | vectortam; 10 | 11 | int get(string x) 12 | { 13 | int sum = 0; 14 | for(int i = 0 ; i < x.size(); i++) sum += (x[i] != ' '); 15 | return sum; 16 | } 17 | 18 | int main() 19 | { 20 | 21 | scanf("%d%d",&n,&d); 22 | 23 | for(int i = 0 ; i < n ; i++) 24 | { 25 | scanf(" %[^\n]", nome); 26 | 27 | char letra = tolower(nome[0]); 28 | 29 | int tecnica = get(nome); 30 | 31 | mp[letra] = max(mp[letra], tecnica); 32 | } 33 | 34 | int ans = 0; 35 | 36 | for(char a = 'a'; a <= 'z'; a++) 37 | { 38 | tam.push_back(mp[a]); 39 | } 40 | 41 | sort(tam.begin(), tam.end(), greater()); 42 | 43 | int limite = min((int)tam.size(), d); 44 | 45 | for(int i = 0 ; i < limite; i++) 46 | { 47 | ans += tam[i]; 48 | //cout << tam[i] << endl; 49 | } 50 | printf("%d\n", ans); 51 | return 0; 52 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2019/solucoes-samuel/I.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int n,m; 6 | 7 | 8 | struct cara 9 | { 10 | int v; 11 | bool vida; 12 | 13 | bool operator <(const cara& q) const 14 | { 15 | if(vida == q.vida) return v > q.v; 16 | return vida; 17 | } 18 | 19 | }caras[10005]; 20 | 21 | int main() 22 | { 23 | scanf("%d%d",&n,&m); 24 | int a = 0; 25 | for(int i = 0 ; i < n ; i++) 26 | { 27 | for(int j = 0 ; j < m ; j++) 28 | { 29 | string g; 30 | cin >> g; 31 | caras[a].v = g[0]-'0'; 32 | caras[a].vida = (g[1] == 'V')? true : false; 33 | a++; 34 | } 35 | } 36 | sort(caras, caras + a); 37 | 38 | for(int i = 0 ; i < a ; i++) printf("%c%c\n", caras[i].v + '0', caras[i].vida ? 'V' : 'D'); 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2019/solucoes-samuel/J.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | const int N = 4005; 6 | 7 | int n, m, q; 8 | int g[N][N]; 9 | 10 | int main() 11 | { 12 | 13 | memset(g, 0, sizeof g); 14 | scanf("%d %d %d", &n, &m, &q); 15 | for(int i = 0; i < m; ++i) 16 | { 17 | int x, y; scanf("%d%d", &x, &y); x--; y--; 18 | 19 | g[x][y] = 1; 20 | g[y][x] = 1; 21 | } 22 | 23 | for(int k = 0; k < n; ++k) 24 | { 25 | for(int i = 0; i < n; ++i) 26 | { 27 | for(int j = 0; j < n; ++j) 28 | { 29 | g[i][j] |= (g[i][k] & g[k][j]); 30 | } 31 | } 32 | } 33 | while(q--) 34 | { 35 | int a, b; scanf("%d %d", &a, &b); a--; b--; 36 | 37 | puts(g[a][b] ? "Lets que lets" : "Deu ruim"); 38 | } 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2019/solucoes-samuel/L.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | using namespace std; 4 | 5 | 6 | ll _sieve_size; 7 | bitset<20000010> bs; 8 | vector primes; 9 | 10 | bool ehprimo(long long n) 11 | { 12 | if(n % 2 == 0) return false; 13 | for(int i = 3 ; i <= sqrt(n); i+=2) 14 | { 15 | if(n % i ==0) 16 | { 17 | //printf("%d\n",i); 18 | return false; 19 | } 20 | } 21 | return true; 22 | } 23 | 24 | ll n; 25 | 26 | 27 | 28 | int main() 29 | { 30 | 31 | cin >> n; 32 | 33 | if(n == 2||ehprimo(n)) printf("1\n"); 34 | else if(n%2 == 0 || ehprimo(n-2)) 35 | printf("2\n"); 36 | else 37 | printf("3\n"); 38 | 39 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2019/solucoes-samuel/L_junior.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define N 101010 6 | 7 | vector prime; 8 | bitsetbs; 9 | 10 | void sieve(){ 11 | bs.set(); bs[0] = bs[1] = 0; 12 | for(int i=2; i> n; 48 | cout << solve(n) << endl; 49 | } -------------------------------------------------------------------------------- /Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2019/solucoes-samuel/Soluções OLIP 2019.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Contests/Olimpíada Interna de Programação do IFSULDEMINAS - OLIP 2019/solucoes-samuel/Soluções OLIP 2019.pdf -------------------------------------------------------------------------------- /Contests/V Maratona Norte Mineira de Programação Open Contest/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "(gdb) Launch", 9 | "type": "cppdbg", 10 | "request": "launch", 11 | "program": "enter program name, for example ${workspaceFolder}/a.exe", 12 | "args": [], 13 | "stopAtEntry": false, 14 | "cwd": "${workspaceFolder}", 15 | "environment": [], 16 | "externalConsole": true, 17 | "MIMode": "gdb", 18 | "miDebuggerPath": "/path/to/gdb", 19 | "setupCommands": [ 20 | { 21 | "description": "Enable pretty-printing for gdb", 22 | "text": "-enable-pretty-printing", 23 | "ignoreFailures": true 24 | } 25 | ] 26 | } 27 | ] 28 | } -------------------------------------------------------------------------------- /Contests/V Maratona Norte Mineira de Programação Open Contest/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define l length() 19 | #define S second 20 | #define PB push_back 21 | #define MP make_pair 22 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 23 | 24 | using namespace std; 25 | 26 | int main(){ 27 | double a = 3.14; 28 | cout << modf(a, 2); 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Contests/V Maratona Norte Mineira de Programação Open Contest/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define l length() 19 | #define S second 20 | #define PB push_back 21 | #define MP make_pair 22 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 23 | 24 | using namespace std; 25 | 26 | int main(){ 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Contests/V Maratona Norte Mineira de Programação Open Contest/Editorial - Maratona Mineira de Programação 2018.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Contests/V Maratona Norte Mineira de Programação Open Contest/Editorial - Maratona Mineira de Programação 2018.pdf -------------------------------------------------------------------------------- /Contests/V Maratona Norte Mineira de Programação Open Contest/G.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define l length() 19 | #define S second 20 | #define PB push_back 21 | #define MP make_pair 22 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 23 | 24 | using namespace std; 25 | 26 | int main(){ 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Contests/V Maratona Norte Mineira de Programação Open Contest/L.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define l length() 19 | #define S second 20 | #define PB push_back 21 | #define MP make_pair 22 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 23 | 24 | using namespace std; 25 | 26 | int main(){ 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Contests/V Maratona Norte Mineira de Programação Open Contest/Resoluções/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | const int N = 100005,oo = 0x3f3f3f3f; 6 | 7 | int n,m,k; 8 | long long ans,homi[N],muie[N]; 9 | 10 | int main(){ 11 | while(~scanf("%d%d%d",&n,&m,&k)){ 12 | ans = 0; 13 | memset(homi,0,sizeof homi); 14 | memset(muie,0,sizeof muie); 15 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | const int N = 100005,oo = 0x3f3f3f3f; 6 | int x,y,m,a,b; 7 | 8 | int main(){ 9 | while(~scanf("%d%d%d",&x,&y,&m)){ 10 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | const int N = 100005,oo = 0x3f3f3f3f; 6 | 7 | int n,x,num[N]; 8 | 9 | int main(){ 10 | while(~scanf("%d%d",&n,&x)){ 11 | vector ans; 12 | for(int i=0;i()); 20 | printf("%.1lf\n",ans[x-1]/3.0); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Contests/V Maratona Norte Mineira de Programação Open Contest/Resoluções/H.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | const int N = 100005,oo = 0x3f3f3f3f; 6 | double media,val[N],ans; 7 | int qt,h,m; 8 | 9 | 10 | int main(){ 11 | while(~scanf("%d%d",&h,&m)){ 12 | qt = (h*60)/m; 13 | ans = media = 0; 14 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | const long long N = 5005,oo = 0x3f3f3f3f; 6 | int n,m; 7 | long long dp[N],qt[N],val[N]; 8 | 9 | long long pd(int i){ 10 | if(dp[i] != -1) return dp[i]; 11 | if(i == 0) return 0; 12 | long long ans = -oo; 13 | for(int j=0;j= qt[j]) ans = max(ans,val[j]+pd(i-qt[j])); 15 | } 16 | return dp[i] = ans; 17 | } 18 | 19 | int main(){ 20 | while(~scanf("%d%d",&n,&m)){ 21 | for(int i=0;i<=2005;i++){ 22 | dp[i] = -1; 23 | } 24 | for(int i=0;i 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define S second 19 | #define PB push_back 20 | #define MP make_pair 21 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 22 | 23 | using namespace std; 24 | 25 | int main(){ 26 | #ifndef ONLINE_JUDGE 27 | freopen("inputf.txt", "r", stdin); 28 | freopen("outputf.txt", "w", stdout); 29 | #endif 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Contests/VII Maratona Mineira de Programação - Open Contest/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define S second 19 | #define PB push_back 20 | #define MP make_pair 21 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 22 | 23 | using namespace std; 24 | 25 | int main(){ 26 | #ifndef ONLINE_JUDGE 27 | freopen("input.txt", "r", stdin); 28 | freopen("output.txt", "w", stdout); 29 | #endif 30 | 31 | 32 | } -------------------------------------------------------------------------------- /Contests/VII Maratona Mineira de Programação - Open Contest/B.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Contests/VII Maratona Mineira de Programação - Open Contest/B.cpp -------------------------------------------------------------------------------- /Contests/VII Maratona Mineira de Programação - Open Contest/E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define S second 19 | #define PB push_back 20 | #define MP make_pair 21 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 22 | 23 | using namespace std; 24 | 25 | int main(){ 26 | #ifndef ONLINE_JUDGE 27 | freopen("inputf.txt", "r", stdin); 28 | freopen("outputf.txt", "w", stdout); 29 | #endif 30 | 31 | int n; 32 | 33 | cin >> n; 34 | 35 | vector > valores; 36 | 37 | forn(i, n){ 38 | valores.push_back(make_pair(i+1, i+1)); 39 | } 40 | 41 | int excluidos[n]; 42 | 43 | forn(i, n){ 44 | int atual; 45 | cin >> atual; 46 | valores.erase(valores.begin()+atual-1); 47 | } 48 | 49 | cout << "a" << endl; 50 | 51 | 52 | return 0; 53 | } -------------------------------------------------------------------------------- /Contests/VII Maratona Mineira de Programação - Open Contest/F.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Contests/VII Maratona Mineira de Programação - Open Contest/F.cpp -------------------------------------------------------------------------------- /Contests/VII Maratona Mineira de Programação - Open Contest/H.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Contests/VII Maratona Mineira de Programação - Open Contest/H.cpp -------------------------------------------------------------------------------- /Contests/VII Maratona Mineira de Programação - Open Contest/I.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Contests/VII Maratona Mineira de Programação - Open Contest/I.cpp -------------------------------------------------------------------------------- /Contests/VII Maratona Mineira de Programação - Open Contest/J.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Contests/VII Maratona Mineira de Programação - Open Contest/J.cpp -------------------------------------------------------------------------------- /Contests/VII Maratona Mineira de Programação - Open Contest/K.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Contests/VII Maratona Mineira de Programação - Open Contest/K.cpp -------------------------------------------------------------------------------- /Contests/VTEX Cup 2019/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Atalhos 9 | #define f first 10 | #define s second 11 | #define pb push_back 12 | #define mp make_pair 13 | #define l length() 14 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 15 | #define fornx(i, x, n) for ( int i = (x); i < (n); ++i ) 16 | 17 | using namespace std; 18 | 19 | int main() { 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Contests/VTEX Cup 2019/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Atalhos 9 | #define f first 10 | #define s second 11 | #define pb push_back 12 | #define mp make_pair 13 | #define l length() 14 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 15 | #define fornx(i, x, n) for ( int i = (x); i < (n); ++i ) 16 | 17 | using namespace std; 18 | 19 | int main() { 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Contests/VTEX Cup 2019/e.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Atalhos 9 | #define f first 10 | #define s second 11 | #define pb push_back 12 | #define mp make_pair 13 | #define l length() 14 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 15 | #define fornx(i, x, n) for ( int i = (x); i < (n); ++i ) 16 | 17 | using namespace std; 18 | 19 | int main() { 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Contests/VTEX Cup 2019/f.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | using namespace std; 9 | 10 | typedef struct { 11 | int c; 12 | int l; 13 | int h; 14 | } Caixa; 15 | 16 | // Definir comparator para a struct 17 | bool cmp(Caixa const & x, Caixa const & y){ 18 | if(x.c < y.c && x.l < y.l && x.h < y.h) { 19 | return true; 20 | }else { 21 | return false; 22 | } 23 | } 24 | 25 | int main(){ 26 | int n; 27 | 28 | cin >> n; 29 | 30 | Caixa caixas[n]; 31 | 32 | for(int i = 0; i < n; i++){ 33 | cin >> caixas[i].c >> caixas[i].l >> caixas[i].h; 34 | } 35 | 36 | sort(&caixas[0],&caixas[n], cmp); 37 | 38 | bool possivel = true; 39 | 40 | for(int i = 0; (i < n-1) && possivel; i++){ 41 | if(!(caixas[i].c < caixas[i+1].c && caixas[i].l < caixas[i+1].l && caixas[i].h < caixas[i+1].h)){ 42 | possivel = false; 43 | } 44 | } 45 | 46 | if(possivel){ 47 | cout << "S\n"; 48 | }else{ 49 | cout << "N\n"; 50 | } 51 | 52 | return 0; 53 | } -------------------------------------------------------------------------------- /Contests/VTEX Cup 2019/h.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Atalhos 9 | #define f first 10 | #define s second 11 | #define pb push_back 12 | #define mp make_pair 13 | #define l length() 14 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 15 | #define fornx(i, x, n) for ( int i = (x); i < (n); ++i ) 16 | 17 | using namespace std; 18 | 19 | int main() { 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Contests/VTEX Cup 2019/i.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Atalhos 9 | #define f first 10 | #define s second 11 | #define pb push_back 12 | #define mp make_pair 13 | #define l length() 14 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 15 | #define fornx(i, x, n) for ( int i = (x); i < (n); ++i ) 16 | 17 | using namespace std; 18 | 19 | int main() { 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Contests/VTEX Cup 2019/j.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Atalhos 9 | #define f first 10 | #define s second 11 | #define pb push_back 12 | #define mp make_pair 13 | #define l length() 14 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 15 | #define fornx(i, x, n) for ( int i = (x); i < (n); ++i ) 16 | 17 | using namespace std; 18 | 19 | int main() { 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Contests/VTEX Cup 2019/k.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Atalhos 9 | #define f first 10 | #define s second 11 | #define pb push_back 12 | #define mp make_pair 13 | #define l length() 14 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 15 | #define fornx(i, x, n) for ( int i = (x); i < (n); ++i ) 16 | 17 | using namespace std; 18 | 19 | int main() { 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Contests/VTEX Cup 2019/l.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Atalhos 9 | #define f first 10 | #define s second 11 | #define pb push_back 12 | #define mp make_pair 13 | #define l length() 14 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 15 | #define fornx(i, x, n) for ( int i = (x); i < (n); ++i ) 16 | 17 | using namespace std; 18 | 19 | int main() { 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Notebook/codes/cin_cout_foreach.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define ld long double 6 | #define INF 0x3f3f3f3f 7 | #define f first 8 | #define s second 9 | #define pb push_back 10 | #define mp make_pair 11 | #define l length() 12 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 13 | #define fornx(i, x, n) for ( int i = (x); i < (n); ++i ) 14 | 15 | using namespace std; 16 | 17 | int main() { 18 | ios::sync_with_stdio(false);cin.tie(NULL); 19 | 20 | vector vec = {0, 1, 2, 3, 4}; 21 | int vec[]= {1, 2, 3, 4, 5}; 22 | vector vec; 23 | vec.resize(n); 24 | 25 | for(const auto &v : vec) 26 | cin >> v; 27 | 28 | for(const auto &v : vec) 29 | cout << v; 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Notebook/codes/divisao-conquista/exponencial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int exp(int x, int y){ 6 | if(y == 0){ 7 | return 1; 8 | } 9 | return x * exp(y - 1); 10 | } 11 | 12 | int main(){ 13 | freopen("input.txt", "r", stdin); 14 | freopen("output.txt", "w", stdout); 15 | 16 | int x, y; 17 | 18 | scanf("%d %d", &x, &y); 19 | 20 | printf("%d^%d = %d\n", x, y, exp(x, y)); 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Notebook/codes/divisao-conquista/fatorial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int fatorial(int x){ 6 | if(x == 1){ 7 | return 1; 8 | } 9 | return x * fatorial(x - 1); 10 | } 11 | 12 | int main(){ 13 | freopen("input.txt", "r", stdin); 14 | freopen("output.txt", "w", stdout); 15 | 16 | int x; 17 | 18 | scanf("%d", &x); 19 | 20 | printf("%d! = %d\n", x, fatorial(x)); 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Notebook/codes/divisao-conquista/fibonnaci.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int fib(int n){ 6 | if(n == 1 || n == 0){ 7 | return 1; 8 | } 9 | return fib(n - 1) + fib(n - 2); 10 | } 11 | 12 | int main(){ 13 | freopen("input.txt", "r", stdin); 14 | freopen("output.txt", "w", stdout); 15 | 16 | int n; 17 | 18 | scanf("%d", &n); 19 | 20 | printf("%d\n", fib(n)); 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Notebook/codes/divisao-conquista/hanoi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | /* 5 | Quantos movimentos são necessários para mover os discos de um 6 | pino para outro? 7 | */ 8 | int hanoi(int x){ 9 | if(x == 1){ 10 | return 1; 11 | } 12 | return 2 * hanoi(x - 1) + 1; 13 | } 14 | 15 | int main(){ 16 | freopen("input.txt", "r", stdin); 17 | freopen("output.txt", "w", stdout); 18 | 19 | int x; 20 | 21 | scanf("%d", &x); 22 | 23 | printf("Quantidade de passos = %d\n", hanoi(x)); 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /Notebook/codes/estruturas/alterar_tamanho_vector.cpp: -------------------------------------------------------------------------------- 1 | V.resize(10); //Muda o tamanho do vector V para 10. -------------------------------------------------------------------------------- /Notebook/codes/estruturas/apagar_elementos_duplicados_vector.cpp: -------------------------------------------------------------------------------- 1 | sort(uniao.begin(), uniao.end()); 2 | uniao.erase(unique(uniao.begin(), uniao.end()), uniao.end()); -------------------------------------------------------------------------------- /Notebook/codes/estruturas/apagar_primeiro_elemento_vector.cpp: -------------------------------------------------------------------------------- 1 | notas.erase(notas.begin()); -------------------------------------------------------------------------------- /Notebook/codes/estruturas/apagar_ultimo_elemento_vector.cpp: -------------------------------------------------------------------------------- 1 | notas.pop_back(); -------------------------------------------------------------------------------- /Notebook/codes/estruturas/busca_vector.cpp: -------------------------------------------------------------------------------- 1 | iterator find(iterator first, iterator last, const T &value); 2 | iterator find_if(iterator first, iterator last, const T &value, TestFunction test); 3 | bool binary_search(iterator first, iterator last, const T &value); 4 | bool binary_search(iterator first, iterator last, const T &value, LessThanOrEqualFunction comp); -------------------------------------------------------------------------------- /Notebook/codes/estruturas/criando_pair_com_dois_valores.cpp: -------------------------------------------------------------------------------- 1 | make_pair(a,b) -------------------------------------------------------------------------------- /Notebook/codes/estruturas/definicao_pair.cpp: -------------------------------------------------------------------------------- 1 | pair P -------------------------------------------------------------------------------- /Notebook/codes/estruturas/fila.cpp: -------------------------------------------------------------------------------- 1 | queue fila; // Declaração da fila 2 | fila.push(10); // Adicionando um elemento ao final da fila 3 | fila.pop(); // Retira o primeiro elemento 4 | fila.front(); // Retorna o primeiro elemento da fila 5 | fila.empty(); // Verifica se a fila está vazia -------------------------------------------------------------------------------- /Notebook/codes/estruturas/fila_prioridades.cpp: -------------------------------------------------------------------------------- 1 | priority_queue< pair > pokemon; 2 | pokemon.push(make_pair(poder, nome)); 3 | pokemon.top(); 4 | pokemon.pop(); -------------------------------------------------------------------------------- /Notebook/codes/estruturas/for_em_map.cpp: -------------------------------------------------------------------------------- 1 | for (map::iterator it=M.begin(); it!=M.end(); ++it){ 2 | cout << "(" << it->first << ", " << it->second << ") "; 3 | } -------------------------------------------------------------------------------- /Notebook/codes/estruturas/leitura_pair.cpp: -------------------------------------------------------------------------------- 1 | cin>>P.first>>P.second -------------------------------------------------------------------------------- /Notebook/codes/estruturas/map.cpp: -------------------------------------------------------------------------------- 1 | // Map é uma variação da estrutura set e sua implementação também é feita utilizando Red- Black Trees. A principal diferença entre um set e um map é o segundo armazena os conjuntos chave, valor e o primeiro apenas chave. 2 | map M; // Declaração 3 | M.insert(make_pair("Alana", 10)); //Inserimos uma variável do tipo pair diretamente no map 4 | M["Alana"] = 10; // Relacionando o valor 10 à chave "Alana" 5 | if(M.find("Alana") != M.end()) //Se a chave "Alana" foi inserida no map 6 | cout<()); -------------------------------------------------------------------------------- /Notebook/codes/estruturas/pilha.cpp: -------------------------------------------------------------------------------- 1 | stack pilha; // Declaração da pilha 2 | pilha.push(10); // Adicionado um elemento ao topo da pilha 3 | pilha.pop(); // Retira o elemento do topo da pilha 4 | pilha.top(); // Retorna o elemento do topo da pilha 5 | pilha.empty(); // Verifica se a pilha está vazia -------------------------------------------------------------------------------- /Notebook/codes/estruturas/set.cpp: -------------------------------------------------------------------------------- 1 | // busca, inserção e exclusão em complexidade O(log n) 2 | // Mantém os elementos ordenados e não permite elementos duplicados 3 | set S; // Declaração do SET 4 | S.insert(10); // Adiciona um elemento 5 | if(S.find(3) != S.end()) // Se 3 está no conjunto 6 | S.erase(10); // Apaga o elemento do SET 7 | // clear(): Apaga todos os elementos. 8 | // size(): Retorna a quantidade de elementos. 9 | // begin(): Retorna um ponteiro para o inicio do set 10 | // end(): Retorna um ponteiro para o final do set -------------------------------------------------------------------------------- /Notebook/codes/estruturas/sort_em_structs.cpp: -------------------------------------------------------------------------------- 1 | // Criar struct 2 | typedef struct { 3 | int moradores; 4 | int gastoss; 5 | int media; 6 | } Imovel; 7 | // Definir comparator para a struct 8 | bool cmp(Imovel const & x,Imovel const & y){ 9 | if(x.media < y.media) { 10 | return true; 11 | }else { 12 | return false; 13 | } 14 | } 15 | // Efetuar o sort no main 16 | Imovel imoveis[10]; 17 | sort(&imoveis[0],&imoveis[10], cmp); -------------------------------------------------------------------------------- /Notebook/codes/estruturas/union-find-pd.cpp: -------------------------------------------------------------------------------- 1 | #define MAXN 100100 2 | 3 | using namespace std; 4 | 5 | int pai[MAXN], peso[MAXN]; 6 | 7 | // funções do Union-Find otimizadas 8 | int find(int x){ 9 | 10 | if(pai[x]==x){ 11 | return x; 12 | } 13 | return pai[x]=find(pai[x]); 14 | } 15 | 16 | void join(int x, int y){ 17 | 18 | x=find(x); 19 | y=find(y); 20 | 21 | if(x==y){ 22 | return; 23 | } 24 | 25 | if(peso[x]peso[y]){ 29 | pai[y]=x; 30 | } 31 | 32 | if(peso[x]==peso[y]){ 33 | 34 | pai[x]=y; 35 | peso[y]++; 36 | } 37 | } 38 | for(int i = 0; i < n; i++){ 39 | pai[i] = i; 40 | } 41 | memset(peso, 1, sizeof peso); -------------------------------------------------------------------------------- /Notebook/codes/estruturas/utilizando_pair_de_pair.cpp: -------------------------------------------------------------------------------- 1 | pair> P; //Cria uma variável pair 2 | P.first = "Joao"; //Nome de um aluno 3 | P.second.first = 8.2; //Primeira nota do aluno 4 | P.second.second = 10; //Segunda nota do aluno -------------------------------------------------------------------------------- /Notebook/codes/estruturas/verifica_se_elemento_existe_vector.cpp: -------------------------------------------------------------------------------- 1 | // O código abaixo verifica se o número 1 existe no vetor uniao (retorna true se existe, falso se não existe) 2 | find(uniao.begin(), uniao.end(), 1) != uniao.end() -------------------------------------------------------------------------------- /Notebook/codes/grafos/caminho_euleniano.cpp: -------------------------------------------------------------------------------- 1 | vector caminho; // guardará nosso Caminho Euleriano (invertido) 2 | vector vizinhos[MAXN]; // nossa lista de adjacência 3 | map< pair, bool > deletada; // mapa que checa se a aresta já foi deletada 4 | void acha_caminho(int v){ 5 | for(int i = 0;i < (int)vizinhos[v].size();i++){ 6 | int viz = vizinhos[v][i]; 7 | if( deletada[make_pair(v, viz)] == true ) 8 | continue; 9 | deletada[make_pair(v, viz)] = true; 10 | deletada[make_pair(viz, v)] = true; 11 | acha_caminho(viz); 12 | } 13 | caminho.push_back(v); 14 | } -------------------------------------------------------------------------------- /Notebook/codes/grafos/dijkstra_matriz.cpp: -------------------------------------------------------------------------------- 1 | #define MAX 999999999 2 | #define max 501 3 | 4 | using namespace std; 5 | 6 | int g[max][max], vertices; 7 | 8 | int dijkstra(int origem, int destino) { 9 | int minimo, atual; 10 | int passou[max], pred[max],custo[max]; 11 | for (int i=1; i<=vertices;i++) { 12 | pred[i]=-1; 13 | custo[i]=MAX; 14 | passou[i]=0; 15 | } 16 | custo[origem] = 0; 17 | atual = origem; 18 | while (atual != destino) { 19 | for (int i=1; i<=vertices; i++) { 20 | if (custo[i] > custo[atual] + g[atual][i]) { 21 | custo[i] = custo[atual] + g[atual][i]; 22 | } 23 | } 24 | minimo = MAX; 25 | passou[atual]=1; 26 | for (int i=1; i<=vertices; i++) { 27 | if ((custo[i] vizinhos[MAXN]; // a lista de adjacência de cada vértice 3 | int cor[MAXN]; 4 | // a cor de cada vértice. Inicialmente, cor[i] = -1 para todos os vértices. 5 | // definimos cor[i] = 0 como sendo azul e cor[i] = 1 como sendo rosa. 6 | void colore(int x){ 7 | cor[x] = 0; 8 | vector fila; 9 | fila.push_back(x); 10 | int pos = 0; 11 | while(pos < (int)fila.size()){ // BFS 12 | int atual = fila[pos]; 13 | pos++; 14 | for(int i = 0;i < (int)vizinhos[atual].size();i++){ 15 | int v = vizinhos[atual][i]; 16 | if(cor[v] == -1){ 17 | cor[v] = 1 - cor[atual]; 18 | fila.push_back(v); // adicionamos v a fila da BFS 19 | } 20 | } 21 | } 22 | } 23 | bool checa_bipartido(){ 24 | for(int i = 1;i <= n;i++){ 25 | if(cor[i] == -1){ 26 | colore(i); 27 | } 28 | } 29 | for(int i = 1;i <= n;i++){ 30 | for(int j = 0;j < (int)vizinhos[i].size();j++){ 31 | int v = vizinhos[i][j]; 32 | if(cor[i] == cor[v]) 33 | return false; 34 | } 35 | } 36 | return true; 37 | } -------------------------------------------------------------------------------- /Notebook/codes/grafos/lca.cpp: -------------------------------------------------------------------------------- 1 | int LCA(int u, int v){ 2 | 3 | if(nivel[u] < nivel[v]) swap(u, v); // isto é para definir u como estando mais abaixo 4 | 5 | // vamos agora fazer nivel[u] ser 6 | // igual nivel[v], subindo pelos 7 | // ancestrais de u 8 | 9 | for(int i = MAXL-1;i >= 0;i--) 10 | if(nivel[u] - (1<= nivel[v]) 11 | u = ancestral[u][i]; 12 | 13 | // agora, u e v estão no mesmo nível 14 | if(u == v) return u; // se eles forem o mesmo nó já achamos nossa resposta 15 | 16 | // subimos o máximo possível de forma 17 | // que os dois NÃO passem a ser iguais 18 | 19 | for(int i = MAXL-1;i >= 0;i--) 20 | if(ancestral[u][i] != -1 && ancestral[u][i] != ancestral[v][i]){ 21 | u = ancestral[u][i]; 22 | v = ancestral[v][i] 23 | } 24 | 25 | // como subimos o máximo possível 26 | // sabemos que u != v e que pai[u] == pai[v] 27 | // logo, LCA(u, v) == pai[u] == pai[v] 28 | 29 | return ancestral[u][0]; 30 | } -------------------------------------------------------------------------------- /Notebook/codes/grafos/lista_adjacencia.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/codes/grafos/lista_adjacencia.cpp -------------------------------------------------------------------------------- /Notebook/codes/grafos/lista_de_arestas.cpp: -------------------------------------------------------------------------------- 1 | struct t_aresta{ 2 | int dis; 3 | int x, y; 4 | }; 5 | 6 | t_aresta aresta[MAXM]; 7 | 8 | -------------------------------------------------------------------------------- /Notebook/codes/grafos/matriz_adjacencia.cpp: -------------------------------------------------------------------------------- 1 | memset(grafo, 0, sizeof(grafo[0][0]) * 10 * 10) 2 | int grafo[10][10]; 3 | 4 | grafo[1][2] = grafo[2][1] = 1; 5 | grafo[1][3] = grafo[3][1] = 1; 6 | grafo[1][6] = grafo[6][1] = 1; 7 | grafo[2][3] = grafo[3][2] = 1; 8 | grafo[3][4] = grafo[4][3] = 1; -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/a_pow_b_mod_p.cpp: -------------------------------------------------------------------------------- 1 | long powmod(long base, long exp, long modulus) { 2 | base %= modulus; 3 | long result = 1; 4 | while (exp > 0) { 5 | if (exp & 1) result = (result * base) % modulus; 6 | base = (base * base) % modulus; 7 | exp >>= 1; 8 | } 9 | return result; 10 | } 11 | -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/ab_mod_p.cpp: -------------------------------------------------------------------------------- 1 | long powmod(long base, long exp, long modulus) { 2 | base %= modulus; 3 | long result = 1; 4 | 5 | while (exp > 0) { 6 | if (exp & 1) result = (result * base) % modulus; 7 | base = (base * base) % modulus; 8 | exp >>= 1; 9 | } 10 | 11 | return result; 12 | } -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/adc_notacao_cient.cpp: -------------------------------------------------------------------------------- 1 | cout << scientific => 5e+2; -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/and_nos_bits.cpp: -------------------------------------------------------------------------------- 1 | // a = 10110; b = 10011; a&b = 10010 -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/arrendondamento_cima.cpp: -------------------------------------------------------------------------------- 1 | ceil(numero) -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/casas_decimais_fixas.cpp: -------------------------------------------------------------------------------- 1 | cout << fixed << setprecision(2); => 5.00; -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/check_bit_is_set.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/codes/matematica_computacional/check_bit_is_set.cpp -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/check_is_power_2.cpp: -------------------------------------------------------------------------------- 1 | bool is_power_of_two(int x) { 2 | if (x == 0) return 0; 3 | return ((x&(x - 1)) == 0) 4 | } 5 | -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/clear_bit.cpp: -------------------------------------------------------------------------------- 1 | int x, i; 2 | cin >> x >> i; 3 | x |= (1 << i); // Primeiro eu ligo o bit, caso ele esteja desligado 4 | x ^= (1 << i); // Depois desligo o bit 5 | -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/comparacao_double.cpp: -------------------------------------------------------------------------------- 1 | bool comparaDouble(double val1, double val2, string cmp) { 2 | if (cmp == "==") { 3 | return fabs(val1 - val2) < EPSILON; 4 | } 5 | else if (cmp == "<=") { 6 | if (fabs(val1 - val2) < EPSILON) { 7 | return true; 8 | } 9 | else { 10 | return val1 <= val2; 11 | } 12 | } 13 | else if (cmp == ">=") { 14 | if (fabs(val1 - val2) < EPSILON) { 15 | return true; 16 | } 17 | else { 18 | return val1 >= val2; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/condicao_existencia_triangulo.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/codes/matematica_computacional/condicao_existencia_triangulo.cpp -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/contar_bits_iguais_1.cpp: -------------------------------------------------------------------------------- 1 | int count_bits(int x) { 2 | int ret = 0; 3 | while (x != 0) { 4 | ++ret; 5 | x -= x & -x; 6 | } 7 | return ret; 8 | } 9 | -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/conversao_int_decimal.cpp: -------------------------------------------------------------------------------- 1 | cout << hex << v 2 | // Considerando v um inteiro -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/crivo_erastotenes.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/codes/matematica_computacional/crivo_erastotenes.cpp -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/desliga_bit.cpp: -------------------------------------------------------------------------------- 1 | int x, i; 2 | cin >> x >> i; 3 | x |= (1 << i); // Primeiro eu ligo o bit, caso ele esteja desligado 4 | x ^= (1 << i); // Depois desligo o bit -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/digital-root-x.cpp: -------------------------------------------------------------------------------- 1 | digitalRoot = x % 9 2 | digitalRoot = ((x-1) % 9) + 1 -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/div_float_double.cpp: -------------------------------------------------------------------------------- 1 | // 1/6=0 2 | // 1.0/6.0=0,1666667 -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/div_numeros_inteiros_resto_negativo.cpp: -------------------------------------------------------------------------------- 1 | int a, b, c; 2 | int q, r; 3 | 4 | cin >> a >> b; 5 | 6 | q = a / b; 7 | r = a % b; 8 | 9 | if (r < 0) { 10 | int c, d; 11 | c = (a < 0) ? a * -1 : a; 12 | d = (b < 0) ? b * -1 : b; 13 | 14 | q = (c + d) / d; 15 | r = (c - (q * d))*-1; 16 | 17 | q = (a*b > 0) ? q : q * -1; 18 | } 19 | -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/fatorizacao_primos.cpp: -------------------------------------------------------------------------------- 1 | vector factors(int n) { 2 | vector f; 3 | for (int x = 2; x*x <= n; x++) { 4 | while (n%x == 0) { 5 | f.push_back(x); 6 | n /= x; 7 | } 8 | } 9 | if (n > 1) f.push_back(n); 10 | return f; 11 | } -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/geometria_computacional_basica/area_do_poligono.cpp: -------------------------------------------------------------------------------- 1 | double area(vector p){ 2 | double ret = 0; 3 | for(int i = 2; i < p.size(); ++i){ 4 | ret += cross(p[i] - p[0], p[i - 1] - p[0])/2; 5 | } 6 | return abs(ret); 7 | } -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/geometria_computacional_basica/ccw.cpp: -------------------------------------------------------------------------------- 1 | double ccw(point a, point b, point c){ 2 | double ret = cross(b - a, c - b); 3 | return ret < 0; 4 | } -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/geometria_computacional_basica/comparacao_fracoes.cpp: -------------------------------------------------------------------------------- 1 | if(a*d == b*c){ 2 | \\seu código aqui 3 | } 4 | -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/geometria_computacional_basica/distancia_entre_dois_pontos.cpp: -------------------------------------------------------------------------------- 1 | double dist(point a, point b){ 2 | point c = a - b; 3 | return sqrt(c.x*c.x + c.y*c.y); 4 | } -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/geometria_computacional_basica/distancia_entre_dois_pontos_complex.cpp: -------------------------------------------------------------------------------- 1 | double dist(point a, point b){ 2 | return abs(a - b); 3 | } -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/geometria_computacional_basica/distancia_entre_ponto_e_reta.cpp: -------------------------------------------------------------------------------- 1 | double dist(point a, line b){ 2 | double crs = cross(point(a - b.first), point(b.second - b.first)); 3 | return abs(crs/dist(b.first, b.second)); 4 | } -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/geometria_computacional_basica/ponto_e_vetor_1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define x first 3 | #define y second 4 | 5 | using namespace std; 6 | 7 | typedef pair point; 8 | 9 | point sum(point a, point b){ 10 | point ret; 11 | ret.x = a.x + b.x; 12 | ret.y = a.y + b.y; 13 | return ret; 14 | } 15 | 16 | point neg(point a){ 17 | point ret; 18 | ret.x = -a.x; 19 | ret.y = -a.y; 20 | return ret; 21 | } -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/geometria_computacional_basica/ponto_e_vetor_2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | struct point{ 6 | double x, double y; 7 | point(){} 8 | point(double _x, double _y){ 9 | x = _x; 10 | y = _y; 11 | } 12 | point operator+(const point &oth){ 13 | return point(x + oth.x, y + oth.y); 14 | } 15 | point operator-(const point &oth){ 16 | return point(x - oth.x, y - oth.y); 17 | } 18 | }; -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/geometria_computacional_basica/ponto_e_vetor_complex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define x real() 3 | #define y imag() 4 | 5 | using namespace std; 6 | typedef complex point; -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/geometria_computacional_basica/produto_escalar.cpp: -------------------------------------------------------------------------------- 1 | double dot(point a, point b){ 2 | return a.x*b.x + a.y*b.y; 3 | } -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/geometria_computacional_basica/produto_escalar_complex.cpp: -------------------------------------------------------------------------------- 1 | double dot(point a, point b){ 2 | return (a*conj(b)).x; 3 | } -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/geometria_computacional_basica/produto_vetorial.cpp: -------------------------------------------------------------------------------- 1 | double cross(point a, point b){ 2 | return a.x*b.y - a.y*b.x; 3 | } -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/geometria_computacional_basica/produto_vetorial_complex.cpp: -------------------------------------------------------------------------------- 1 | double cross(point a, point b){ 2 | return (a*conj(b)).y; 3 | } -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/get_lsb.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/codes/matematica_computacional/get_lsb.cpp -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/k-esimo-digital-root-igual-a-x.cpp: -------------------------------------------------------------------------------- 1 | xk = ((k - 1) * 9) + x -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/liga_bit_em_numero.cpp: -------------------------------------------------------------------------------- 1 | // É bem simples, basta o número receber ele or 2 elevado ao bit que queremos setar 2 | int x, i; 3 | cin >> x >> i; 4 | x |= (1 << i); -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/maior_dc.cpp: -------------------------------------------------------------------------------- 1 | int gcd(int a, int b) 2 | { 3 | if (b==0) return a; 4 | else return gcd(b, a%b); 5 | } -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/maior_divisor_comum_GCD.cpp: -------------------------------------------------------------------------------- 1 | int mdc(int a, int b){ 2 | return (b == 0 ? a : mdc(b, a%b)); //b == 0 ? Caso sim, retorne a, caso não, retorne mdc(b, a%b) 3 | } 4 | -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/max_entre_dois_num.cpp: -------------------------------------------------------------------------------- 1 | int max(int a, int b) { return a>b ? a:b; } -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/menor_dc.cpp: -------------------------------------------------------------------------------- 1 | int lcm(int a, int b) 2 | { 3 | return a*b/gcd(a,b); 4 | } -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/menor_divisor_comum_LCM.cpp: -------------------------------------------------------------------------------- 1 | int lcm(int a, int b) 2 | { 3 | return a * b / gcd(a, b); 4 | } 5 | -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/min_entre_dois_num.cpp: -------------------------------------------------------------------------------- 1 | int min(int a, int b) { return a 1) { 4 | res = (res * powmod(p - 1, n / p, p)) % p; 5 | for (int i = 2; i <= n % p; ++i) 6 | res = (res*i) % p; 7 | n /= p; 8 | } 9 | return int(res % p); 10 | } 11 | -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/n_mod_p.cpp: -------------------------------------------------------------------------------- 1 | int factmod (int n, int p) { 2 | long long res = 1; 3 | while (n > 1) { 4 | res = (res * powmod (p-1, n/p, p)) % p; 5 | for (int i=2; i<=n%p; ++i) 6 | res=(res*i) %p; 7 | n /= p; 8 | } 9 | return int (res % p); 10 | } -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/num_casas_decimais_num.cpp: -------------------------------------------------------------------------------- 1 | ceil(log10(numero+1)) -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/num_combi_conj.cpp: -------------------------------------------------------------------------------- 1 | // x = n!/(n-k)!k! -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/num_permutacoes_conj.cpp: -------------------------------------------------------------------------------- 1 | // dados um grupo de 4 pessoas, de quantas formas podemos colocá-los em fila? 2 | // P(n, k) = n!/(n-k)! 3 | // k = número de elementos para permuta; n = número total de elementos -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/or_nos_bits.cpp: -------------------------------------------------------------------------------- 1 | // a = 10010; b = 01110; a|b = 11110 -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/primo_rapido_sqrt_n.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/codes/matematica_computacional/primo_rapido_sqrt_n.cpp -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/set_bit.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/codes/matematica_computacional/set_bit.cpp -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/shift_dir.cpp: -------------------------------------------------------------------------------- 1 | // b = 260; b >>= 3; b = 32, que em binário é 100000 -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/shift_esq.cpp: -------------------------------------------------------------------------------- 1 | // a = 1; a = a << 8; a = 256, que em binário é 100000000 -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/tricks_cmath.cpp: -------------------------------------------------------------------------------- 1 | // Quando um número for muito grande usar powl ao invés de pow. powl terá mais precisão 2 | powl(a, b) 3 | (int)round(p, (1.0/n)) // nth raíz de p -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/xor_nos_bits.cpp: -------------------------------------------------------------------------------- 1 | // a = 10110; b = 10011; a^b = 00101 -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/zera_conteudo_array_1d.cpp: -------------------------------------------------------------------------------- 1 | memset(array, 0, sizeof(array)) -------------------------------------------------------------------------------- /Notebook/codes/matematica_computacional/zera_conteudo_array_2d.cpp: -------------------------------------------------------------------------------- 1 | memset(array, 0, sizeof(array[0][0]) * n * n) -------------------------------------------------------------------------------- /Notebook/codes/outros/busca_binaria.cpp: -------------------------------------------------------------------------------- 1 | // Necessário vetor estar ordenado 2 | int binarySearch(int arr[], int l, int r, int x) 3 | { 4 | if (r >= l) 5 | { 6 | int mid = l + (r - l)/2; 7 | if (arr[mid] == x) 8 | return mid; 9 | if (arr[mid] > x) 10 | return binarySearch(arr, l, mid-1, x); 11 | return binarySearch(arr, mid+1, r, x); 12 | } 13 | return -1; 14 | } -------------------------------------------------------------------------------- /Notebook/codes/outros/formas_escrever_tipos_dados.cpp: -------------------------------------------------------------------------------- 1 | long int == long 2 | long long int == long long 3 | unsigned int == unsigned 4 | unsigned long long int == unsigned long long -------------------------------------------------------------------------------- /Notebook/codes/outros/geraPossibilidadesLetras.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | void geraPossibilidades(int n, int pos, string possibilidade){ 6 | if(pos == n){ 7 | cout << possibilidade << endl; 8 | return; 9 | } 10 | for(char c = 'a'; c <= 'z'; c++){ 11 | possibilidade[pos] = c; 12 | 13 | geraPossibilidades(n, pos+1, possibilidade); 14 | } 15 | } 16 | 17 | int main(){ 18 | int n = 3; 19 | 20 | string possibilidade(n, 'x'); 21 | geraPossibilidades(n, 0, possibilidade); 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Notebook/codes/outros/gerar_numeros_aleatorios.cpp: -------------------------------------------------------------------------------- 1 | srand(time(NULL)); 2 | // generate random numbers between [a,b) 3 | rand() % (b - a) + a; 4 | // generate random numbers between [0,b) 5 | rand() % b; 6 | // generate random permutations 7 | random_permutation(anArray, anArray + 10); 8 | random_permutation(aVector, aVector + 10); -------------------------------------------------------------------------------- /Notebook/codes/outros/inicializar_vetor_com_valor_predefinido.cpp: -------------------------------------------------------------------------------- 1 | // for 1d array, use STL fill_n or fill to initialize array 2 | fill(a, a+size_of_a, value) 3 | fill_n(a, size_of_a, value) 4 | // for 2d array, if want to fill in 0 or -1 5 | memset(a, 0, sizeof(a)); 6 | // otherwise, use a loop of fill or fill_n through every a[i] 7 | fill(a[i], a[i]+size_of_ai, value) // from 0 to number of row. -------------------------------------------------------------------------------- /Notebook/codes/outros/operacoes_para_modificar_sequencias.cpp: -------------------------------------------------------------------------------- 1 | void copy(first, last, result); 2 | void swap(a,b); 3 | void swap(first1, last1, first2); // swap range 4 | void replace(first, last, old_value, new_value); // replace in range 5 | void replace_if(first, last, pred, new_value); // replace in conditions 6 | // pred can be represented in function 7 | // e.x. bool IsOdd (int i) { return ((i%2)==1); } 8 | void reverse(first, last); // reverse a range of elements 9 | void reverse_copy(first, last, result); // copy a reverse of range of elements 10 | void random_shuffle(first, last); // using built-in random generator to shuffle array -------------------------------------------------------------------------------- /Notebook/codes/outros/permutacoes.cpp: -------------------------------------------------------------------------------- 1 | bool next_permutation(iterator first, iterator last); 2 | bool next_permutation(iterator first, iterator last, LessThanOrEqualFunction comp); 3 | bool prev_permutation(iterator first, iterator last); 4 | bool prev_permutation(iterator first, iterator last, LessThanOrEqualFunction comp); -------------------------------------------------------------------------------- /Notebook/codes/programacao_dinamica/corte_haste.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | // tamanho da haste. 6 | int n = 5; 7 | 8 | // Preço para cada tamanho de corte. 9 | // ex. para o tamanho 1 o preço é 2. 10 | int precos_corte[] = {2,4,3,1,5}; 11 | 12 | int i, j; 13 | 14 | // Vetor de memorização. 15 | int memo[n+1]; 16 | memo[0] = 0; // Solução trivial - corte de tamanho zero com preço zero. 17 | 18 | for(i = 1; i <= n; ++i) { 19 | int q = -1; 20 | for(j = 1; j <= i; ++j) { 21 | if(q < (precos_corte[j-1] + memo[i-j])) { 22 | q = precos_corte[j-1]+memo[i-j]; 23 | } 24 | } 25 | memo[i] = q; 26 | } 27 | 28 | // Solução está na última posição do vetor de memorização: 29 | printf("Valor de venda = %d",memo[n]); 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Notebook/codes/programacao_dinamica/fibonnaci.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define MAX 100001 6 | 7 | int memo[MAX]; 8 | 9 | int fib(int n){ 10 | if(n == 1 || n == 0){ 11 | return 1; 12 | } 13 | if(memo[n] == -1){ 14 | return fib(n - 1) + fib(n - 2); 15 | }else{ 16 | return memo[n]; 17 | } 18 | 19 | } 20 | 21 | int main(){ 22 | freopen("input.txt", "r", stdin); 23 | freopen("output.txt", "w", stdout); 24 | 25 | int n; 26 | 27 | memset(memo, -1, sizeof(memo)); 28 | 29 | scanf("%d", &n); 30 | 31 | printf("%d\n", fib(n)); 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Notebook/codes/programacao_dinamica/formigaNoTetraedo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | //#define INFINITO 99999 6 | #define MAX 10001 7 | 8 | float memo[MAX][MAX]; 9 | 10 | 11 | // Complexidade O(n) 12 | float formiga(char v, int falta){ 13 | if(falta == 0){ 14 | if(v == 'D'){ 15 | return 1; 16 | }else{ 17 | return 0; 18 | } 19 | } 20 | 21 | if(memo[v][falta] != -1){ 22 | return memo[v][falta]; 23 | } 24 | 25 | int resposta = 0; 26 | 27 | for(char u = 'A'; u != 'D'; u++){ 28 | if(u == v) continue; // para cada vértice u != v 29 | resposta = resposta + (1/3)*formiga(u, falta-1); 30 | } 31 | memo[v][falta] = resposta; 32 | 33 | return resposta; 34 | } 35 | 36 | int main(){ 37 | int tempo = 2; 38 | int vertices = 4; 39 | 40 | memset(memo, -1, sizeof(memo[0][0]) * (vertices+1) * (tempo+1)); 41 | 42 | printf("%f\n", formiga('D', 2)); 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Notebook/codes/programacao_dinamica/maior_subsequencia_comum.cpp: -------------------------------------------------------------------------------- 1 | using namespace std; 2 | 3 | // defino MAXN como 1010 4 | #define MAXN 1010 5 | 6 | // declaro as variáveis que vou usar 7 | int s1[MAXN], s2[MAXN], tab[MAXN][MAXN]; 8 | 9 | int lcs(int a, int b){ // declaro a função da DP, de nome lcs 10 | 11 | // se já calculamos esse estado da dp antes 12 | if(tab[a][b]>=0) return tab[a][b]; // retornamos o valor salvo para ele 13 | 14 | // se uma das sequências for vazia, retornamos zero 15 | if(a==0 or b==0) return tab[a][b]=0; 16 | 17 | // se s1[a] for igual a s2[b], os retiramos das sequências 18 | if(s1[a]==s2[b]) return 1+lcs(a-1, b-1); // e adicionamos ele à lcs das subsequâncias restantes 19 | 20 | // se forem diferentes, retorno o máximo entre retirar s1[a] ou s1[b] 21 | return tab[a][b]=max(lcs(a-1, b), lcs(a, b-1)); 22 | } -------------------------------------------------------------------------------- /Notebook/codes/programacao_dinamica/maior_subsequencia_comum_2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int max(int a, int b); 4 | 5 | /* Returns length of LCS for X[0..m-1], Y[0..n-1] */ 6 | int lcs( char *X, char *Y, int m, int n ) 7 | { 8 | if (m == 0 || n == 0) 9 | return 0; 10 | if (X[m-1] == Y[n-1]) 11 | return 1 + lcs(X, Y, m-1, n-1); 12 | else 13 | return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n)); 14 | } 15 | 16 | /* Utility function to get max of 2 integers */ 17 | int max(int a, int b) 18 | { 19 | return (a > b)? a : b; 20 | } 21 | 22 | /* Driver program to test above function */ 23 | int main() 24 | { 25 | char X[] = "AGGTAB"; 26 | char Y[] = "GXTXAYB"; 27 | 28 | int m = strlen(X); 29 | int n = strlen(Y); 30 | 31 | printf("Length of LCS is %d", lcs( X, Y, m, n ) ); 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Notebook/codes/programacao_dinamica/minimo_moedas_troco.cpp: -------------------------------------------------------------------------------- 1 | // função que recebe o valor de troco N, o número de moedas disponíveis M, 2 | // e um vetor com as moedas disponíveis m 3 | // essa função deve retornar o número mínimo de moedas, 4 | // de acordo com a solução com Programação Dinamica. 5 | int num_moedas(int N, int M, int * m) { 6 | int dp[N+1]; 7 | 8 | // caso base 9 | dp[0] = 0; 10 | 11 | // sub-problemas 12 | for(int i=1; i<=N; i++) { 13 | // é comum atribuir um valor alto, que concerteza 14 | // é maior que qualquer uma das próximas possibilidades, 15 | // sendo assim substituido 16 | dp[i] = 1000000; 17 | 18 | for(int j=0; j= 0) { 20 | dp[i] = min(dp[i], dp[ i-m[j] ]+1); 21 | } 22 | } 23 | } 24 | 25 | // solução 26 | return dp[N]; 27 | } -------------------------------------------------------------------------------- /Notebook/codes/programacao_dinamica/soma_maxima_intervalo.cpp: -------------------------------------------------------------------------------- 1 | int max_sum(vector s){ 2 | 3 | int resp=0, maior=0; 4 | 5 | for(int i=0;i &c){ 6 | 7 | if(x==0) return 1; 8 | 9 | if(x<0) return 0; 10 | 11 | if(dp[x]>=0) return dp[x]; 12 | 13 | for(int i=0;i> x // converte a string em um float(x = long double) -------------------------------------------------------------------------------- /Notebook/codes/strings/string_streams.cpp: -------------------------------------------------------------------------------- 1 | stringstream s1; 2 | int i = 22; 3 | s1 << "Hello world! " << i; 4 | cout << s1.str() << endl; -------------------------------------------------------------------------------- /Notebook/codes/strings/uppercase_cout.cpp: -------------------------------------------------------------------------------- 1 | cout << uppercase << "a" -------------------------------------------------------------------------------- /Notebook/codes/strings/verificacoes/verifica_caractere_intervalo_A_z.cpp: -------------------------------------------------------------------------------- 1 | (line[i] >= 65 && line[i] <= 90) || (line[i] >= 97 && line[i] <= 122) -------------------------------------------------------------------------------- /Notebook/codes/strings/verificacoes/verifica_string_vazia.cpp: -------------------------------------------------------------------------------- 1 | n.empty() // Retona true ou false -------------------------------------------------------------------------------- /Notebook/codes/template.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define ld long double 6 | #define INF 0x3f3f3f3f 7 | #define f first 8 | #define s second 9 | #define pb push_back 10 | #define mp make_pair 11 | #define l length() 12 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 13 | #define fornx(i, x, n) for ( int i = (x); i < (n); ++i ) 14 | 15 | using namespace std; 16 | 17 | int main() { 18 | ios::sync_with_stdio(false);cin.tie(NULL); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Notebook/figures/estruturas/arvore_de_segmentos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/estruturas/arvore_de_segmentos.png -------------------------------------------------------------------------------- /Notebook/figures/grafos/LCA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/grafos/LCA.png -------------------------------------------------------------------------------- /Notebook/figures/grafos/OT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/grafos/OT.png -------------------------------------------------------------------------------- /Notebook/figures/grafos/agm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/grafos/agm.png -------------------------------------------------------------------------------- /Notebook/figures/grafos/grafos_bipartidos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/grafos/grafos_bipartidos.png -------------------------------------------------------------------------------- /Notebook/figures/grafos/representacao_lista_adj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/grafos/representacao_lista_adj.png -------------------------------------------------------------------------------- /Notebook/figures/grafos/representacao_matriz_adj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/grafos/representacao_matriz_adj.png -------------------------------------------------------------------------------- /Notebook/figures/logo_icpc_mdp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/logo_icpc_mdp.png -------------------------------------------------------------------------------- /Notebook/figures/logo_if_horizontal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/logo_if_horizontal.jpg -------------------------------------------------------------------------------- /Notebook/figures/matematica_computacional/Condicao_existencia_triangulo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/matematica_computacional/Condicao_existencia_triangulo.png -------------------------------------------------------------------------------- /Notebook/figures/matematica_computacional/geometria_basica/distancia_entre_dois_pontos_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/matematica_computacional/geometria_basica/distancia_entre_dois_pontos_1.png -------------------------------------------------------------------------------- /Notebook/figures/matematica_computacional/geometria_basica/distancia_entre_dois_pontos_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/matematica_computacional/geometria_basica/distancia_entre_dois_pontos_2.png -------------------------------------------------------------------------------- /Notebook/figures/matematica_computacional/geometria_basica/equacao_circulo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/matematica_computacional/geometria_basica/equacao_circulo.png -------------------------------------------------------------------------------- /Notebook/figures/matematica_computacional/geometria_basica/equacao_reta.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/matematica_computacional/geometria_basica/equacao_reta.png -------------------------------------------------------------------------------- /Notebook/figures/matematica_computacional/geometria_basica/teorema_tales_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/matematica_computacional/geometria_basica/teorema_tales_1.png -------------------------------------------------------------------------------- /Notebook/figures/matematica_computacional/geometria_basica/teorema_tales_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/matematica_computacional/geometria_basica/teorema_tales_2.png -------------------------------------------------------------------------------- /Notebook/figures/matematica_computacional/geometria_computacional_basica/produto_escalar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/matematica_computacional/geometria_computacional_basica/produto_escalar.png -------------------------------------------------------------------------------- /Notebook/figures/matematica_computacional/geometria_computacional_basica/produto_vetorial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/matematica_computacional/geometria_computacional_basica/produto_vetorial.png -------------------------------------------------------------------------------- /Notebook/figures/outros/Ascii_Table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/outros/Ascii_Table.png -------------------------------------------------------------------------------- /Notebook/figures/outros/cpp_limits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/outros/cpp_limits.png -------------------------------------------------------------------------------- /Notebook/figures/outros/eds_c++.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook/figures/outros/eds_c++.png -------------------------------------------------------------------------------- /Notebook_Maratonas_v1.3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Notebook_Maratonas_v1.3.pdf -------------------------------------------------------------------------------- /Upsolving/A2-Online-Judge/1-Under-1300/110A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string number; 7 | int contador; 8 | 9 | cin >> number; 10 | 11 | contador = 0; 12 | for(int i = 0; i < number.length(); i++){ 13 | if(number[i] == '4' || number[i] == '7'){ 14 | contador++; 15 | } 16 | } 17 | 18 | string contador_string = to_string(contador); 19 | int todos_lucky = 1; 20 | 21 | for(int i = 0; i < contador_string.length(); i++){ 22 | if(!(contador_string[i] == '4' || contador_string[i] == '7')){ 23 | todos_lucky = 0; 24 | break; 25 | } 26 | } 27 | 28 | if(todos_lucky){ 29 | cout << "YES\n"; 30 | }else{ 31 | cout << "NO\n"; 32 | } 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Upsolving/A2-Online-Judge/1-Under-1300/218B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int p, a; 7 | int cmax = 0; 8 | int cmin = 0; 9 | 10 | cin >> p >> a; 11 | 12 | int air1[a], air2[a]; 13 | 14 | for(int i = 0; i < a; i++){ 15 | cin >> air1[i]; 16 | air2[i] = air1[i]; 17 | } 18 | 19 | while(p--){ 20 | sort(air1, air1+a); 21 | sort(air2, air2+a); 22 | int pos = 0; 23 | while(air1[pos] == 0){ 24 | pos++; 25 | } 26 | cmin += air1[pos]--; 27 | cmax += air2[a-1]--; 28 | } 29 | cout << cmax << " " << cmin << "\n"; 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Upsolving/A2-Online-Judge/1-Under-1300/263A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int posI, posJ, n, posFinal; 7 | 8 | for(int i = 1; i <= 5; i++){ 9 | for(int j = 1; j <= 5; j++){ 10 | scanf("%d", &n); 11 | if(n == 1){ 12 | posI = i; 13 | posJ = j; 14 | } 15 | } 16 | } 17 | 18 | posFinal = abs(3-posI)+abs(3-posJ); 19 | 20 | printf("%d\n", posFinal); 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Upsolving/A2-Online-Judge/1-Under-1300/266A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | string table; 8 | int contador = 0; 9 | 10 | cin >> n; 11 | cin.ignore(); 12 | cin >> table; 13 | 14 | for(int i = 0; i < n-1; i++){ 15 | if(table[i] == table[i+1]){ 16 | contador++; 17 | } 18 | } 19 | 20 | cout << contador << endl; 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Upsolving/A2-Online-Judge/1-Under-1300/266B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n, t; 7 | string fila, filaNova; 8 | 9 | scanf("%d %d ", &n, &t); 10 | cin >> fila; 11 | 12 | while(t--){ 13 | filaNova = fila; 14 | for(int i = 0; i < n-1; i++){ 15 | if(fila[i] == 'B' && fila[i+1] == 'G'){ 16 | filaNova[i] = 'G'; 17 | filaNova[i+1] = 'B'; 18 | } 19 | } 20 | fila = filaNova; 21 | } 22 | 23 | cout << fila << endl; 24 | 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Upsolving/A2-Online-Judge/1-Under-1300/271A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int nd = 0; 6 | 7 | int checaNumero(int n){ 8 | int aux = n; 9 | int digito; 10 | int digitos[10]; 11 | 12 | memset(digitos, 0, 10*sizeof(digitos[0])); 13 | 14 | while(aux > 0){ 15 | digito = aux%10; 16 | if(digitos[digito] > 0) 17 | return false; 18 | else 19 | digitos[digito]++; 20 | 21 | aux = aux/10; 22 | } 23 | nd = n; 24 | return true; 25 | } 26 | 27 | int main(){ 28 | int n; 29 | 30 | scanf("%d", &n); 31 | 32 | while(1){ 33 | if(checaNumero(++n)) 34 | break; 35 | } 36 | 37 | printf("%d\n", nd); 38 | 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Upsolving/A2-Online-Judge/1-Under-1300/277B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int crescente, decrescente, n, q; 7 | 8 | crescente = decrescente = 0; 9 | 10 | scanf("%d", &n); 11 | 12 | int vetor[n]; 13 | 14 | for(int i = 0; i < n; i++){ 15 | scanf("%d", &vector[i]); 16 | } 17 | 18 | scanf("%d", &q); 19 | 20 | int qAtual; 21 | 22 | for(int i = 0){ 23 | 24 | } 25 | 26 | 27 | printf("%d %d\n", crescente, decrescente); 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Upsolving/A2-Online-Judge/1-Under-1300/281A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string word; 7 | 8 | cin >> word; 9 | 10 | word[0] = toupper(word[0]); 11 | 12 | cout << word << "\n"; 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Upsolving/A2-Online-Judge/1-Under-1300/282A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | int x = 0; 8 | string op; 9 | 10 | cin >> n; 11 | 12 | while(n--){ 13 | cin >> op; 14 | if(op[0] == '+' || op[2] == '+'){ 15 | x++; 16 | }else{ 17 | x--; 18 | } 19 | } 20 | cout << x << "\n"; 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Upsolving/A2-Online-Judge/1-Under-1300/32B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string notation; 7 | string message; 8 | 9 | cin >> notation; 10 | 11 | for(int i = 0; i < notation.length(); i++){ 12 | if(notation[i] == '.'){ 13 | message += '0'; 14 | }else{ 15 | if(notation[i+1] == '.'){ 16 | message+= '1'; 17 | i++; 18 | }else{ 19 | message+= '2'; 20 | i++; 21 | } 22 | } 23 | } 24 | 25 | cout << message << endl; 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Upsolving/A2-Online-Judge/1-Under-1300/59A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int upper, lower; 7 | string word; 8 | 9 | cin >> word; 10 | 11 | upper = lower = 0; 12 | 13 | for(int i = 0; i < word.length(); i++){ 14 | if(word[i] >= 'a' && word[i] <= 'z'){ 15 | lower++; 16 | } 17 | if(word[i] >= 'A' && word[i] <= 'Z'){ 18 | upper++; 19 | } 20 | } 21 | 22 | if(lower >= upper){ 23 | transform(word.begin(), word.end(), word.begin(), ::tolower); 24 | }else{ 25 | transform(word.begin(), word.end(), word.begin(), ::toupper); 26 | } 27 | 28 | cout << word << "\n"; 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Upsolving/A2-Online-Judge/1-Under-1300/61A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | 9 | string n1,n2, saida; 10 | 11 | cin >> n1 >> n2; 12 | 13 | for(int i = 0; i < n1.length(); i++){ 14 | cout << ((n1[i] != n2[i]) ? '1' : '0'); 15 | } 16 | 17 | cout << "\n"; 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Upsolving/A2-Online-Judge/1-Under-1300/69A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n, x, y, z; 7 | int xt, yt, zt; 8 | 9 | scanf("%d", &n); 10 | 11 | x = y = z = 0; 12 | 13 | while(n--){ 14 | scanf("%d %d %d", &xt, &yt, &zt); 15 | 16 | x+=xt; 17 | y+=yt; 18 | z+=zt; 19 | } 20 | 21 | if(x == 0 && y == 0 && z == 0){ 22 | printf("YES\n"); 23 | }else{ 24 | printf("NO\n"); 25 | } 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Upsolving/A2-Online-Judge/1-Under-1300/71A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n, l; 7 | string x; 8 | 9 | scanf("%d ", &n); 10 | 11 | while(n--){ 12 | cin >> x; 13 | 14 | l = x.length(); 15 | if(l > 10){ 16 | cout << x[0] << l-2 << x[l-1] << "\n"; 17 | }else{ 18 | cout << x << "\n"; 19 | } 20 | } 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Upsolving/A2-Online-Judge/1-Under-1300/80A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | 7 | #define MAXN 10000009 8 | 9 | ll sievesize; 10 | bitset bs; 11 | vector primes; 12 | 13 | void sieve(ll n) { 14 | sievesize = n + 1; 15 | bs.set(); 16 | bs[0] = bs[1] = 0; 17 | for (ll i = 2; i <= sievesize; i++) { 18 | if (bs[i]) { 19 | for (ll j = i*i; j <= (ll)sievesize; j+=i) bs[j] = 0; 20 | primes.push_back(i); 21 | } 22 | } 23 | } 24 | 25 | int main(){ 26 | sieve(55); 27 | 28 | int n, m; 29 | vector::iterator it; 30 | 31 | cin >> n >> m; 32 | 33 | it = find(primes.begin(), primes.end(), n); 34 | ++it; 35 | 36 | if((*it) == m){ 37 | cout << "YES\n"; 38 | }else{ 39 | cout << "NO\n"; 40 | } 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /Upsolving/Codeforces/1077A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long res, a,b,k; 7 | int n; 8 | int direita = 1; 9 | 10 | scanf("%d", &n); 11 | 12 | while(n--){ 13 | scanf("%lld %lld %lld", &a, &b, &k); 14 | 15 | if((k%2) == 0){ 16 | res = ((k/2)*a) - ((k/2)*b); 17 | }else{ 18 | res = (((k/2)+1)*a) - ((k/2)*b); 19 | } 20 | 21 | printf("%lld\n", res); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Upsolving/Codeforces/1092A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int t, n, k; 7 | int resto; 8 | int n_ocorrencias; 9 | char letra_atual; 10 | int contador; 11 | 12 | scanf("%d", &t); 13 | 14 | for(int i = 0; i < t; i++){ 15 | scanf("%d %d", &n, &k); 16 | n_ocorrencias = floor(n/k); 17 | resto = n%k; 18 | if(resto > 0){ 19 | n-=resto; 20 | } 21 | letra_atual = 'a'; 22 | contador = 0; 23 | for(int j = 0; j < n; j++){ 24 | printf("%c", letra_atual); 25 | if(++contador == n_ocorrencias){ 26 | contador = 0; 27 | letra_atual++; 28 | } 29 | } 30 | if(resto > 0){ 31 | letra_atual--; 32 | for(int i = 0; i < resto; i++){ 33 | printf("%c", letra_atual); 34 | } 35 | } 36 | printf("\n", n_ocorrencias); 37 | } 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Upsolving/Codeforces/1092B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | vector students; 8 | int sa; 9 | int contadorProblemas = 0; 10 | 11 | scanf("%d", &n); 12 | 13 | for(int i = 0; i < n; i++){ 14 | scanf("%d", &sa); 15 | students.push_back(sa); 16 | } 17 | sort(students.begin(), students.end()); 18 | 19 | for(int i = 0; i < n; i+=2){ 20 | contadorProblemas += students.at(i+1)-students.at(i); 21 | } 22 | printf("%d\n", contadorProblemas); 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Upsolving/Codeforces/1107A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | /* 7 | freopen("input.txt", "r", stdin); 8 | freopen("output.txt", "w", stdout); 9 | */ 10 | 11 | int q; 12 | int n; 13 | string s; 14 | char d1; 15 | 16 | scanf("%d ", &q); 17 | 18 | while(q--){ 19 | cin >> n >> s; 20 | 21 | if(n == 2 && s[0] >= s[1]){ 22 | cout << "NO\n"; 23 | }else{ 24 | cout << "YES\n"; 25 | cout << "2\n"; 26 | cout << s[0] << " " << s.substr(1) << "\n"; 27 | } 28 | } 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Upsolving/Codeforces/1107B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define ll long long 6 | 7 | int main(){ 8 | /* 9 | freopen("input.txt", "r", stdin); 10 | freopen("output.txt", "w", stdout); 11 | */ 12 | 13 | ll n, k, x; 14 | 15 | cin >> n; 16 | 17 | while(n--){ 18 | cin >> k >> x; 19 | 20 | cout << ((k - 1)*9) + x << "\n"; 21 | } 22 | 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Upsolving/Codeforces/1107C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define ll long long 6 | 7 | int main(){ 8 | /* 9 | freopen("input.txt", "r", stdin); 10 | freopen("output.txt", "w", stdout); 11 | */ 12 | 13 | int n, k; 14 | 15 | vector seq; 16 | string buttons; 17 | ll somaTotal = 0; 18 | 19 | cin >> n >> k; 20 | seq.resize(n); 21 | 22 | // cooool 23 | for(int &a : seq){ 24 | cin >> a; 25 | } 26 | 27 | cin >> buttons; 28 | 29 | for(int i = 0, j = 0; i < n; i = j){ 30 | while(j < n && buttons[j] == buttons[i]) 31 | j++; 32 | 33 | sort(seq.begin()+i, seq.begin()+j); 34 | reverse(seq.begin()+i, seq.begin()+j); 35 | 36 | //cout << i << "-" << min(j, i+k) << " = "; 37 | 38 | for(int z = i; z < min(j, i+k); z++){ 39 | somaTotal+=seq[z]; 40 | } 41 | //cout << somaTotal << endl; 42 | } 43 | 44 | cout << somaTotal << "\n"; 45 | 46 | 47 | return 0; 48 | } -------------------------------------------------------------------------------- /Upsolving/NEPS Academy/Estruturas de Dados/Fila/Copa_Do_Mundo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | /*#ifndef ONLINE_JUDGE 7 | freopen("input.txt", "r", stdin); 8 | freopen("output.txt", "w", stdout); 9 | #endif*/ 10 | 11 | queue times; 12 | 13 | for(char c = 'A'; c != 'Q'; c++){ 14 | times.push(c); 15 | } 16 | 17 | for(int i = 0; i < 15; i++){ 18 | int t1, t2; 19 | scanf("%d %d", &t1, &t2); 20 | char tim1, tim2; 21 | tim1 = times.front(); 22 | times.pop(); 23 | tim2 = times.front(); 24 | times.pop(); 25 | if(t1 > t2){ 26 | times.push(tim1); 27 | }else{ 28 | times.push(tim2); 29 | } 30 | } 31 | 32 | cout << times.front() << endl; 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Upsolving/NEPS Academy/Estruturas de Dados/Pilha/expressoes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | verificaIgualdade(char c1, char c2){ 6 | if(c1 == '['){ 7 | return c2 == ']'; 8 | }else if(c1 == '{'){ 9 | return c2 == '}'; 10 | }else 11 | return c2 == ')'; 12 | } 13 | 14 | int main(){ 15 | #ifndef ONLINE_JUDGE 16 | freopen("input.txt", "r", stdin); 17 | freopen("output.txt", "w", stdout); 18 | #endif 19 | 20 | int n; 21 | string expressao; 22 | 23 | scanf("%d", &n); 24 | 25 | while(n--){ 26 | cin >> expressao; 27 | 28 | cout << expressao << endl; 29 | 30 | for(int i = expressao.size()/2, j = (expressao.size()/2)-1; i < expressao.size(); i++, j--){ 31 | if(expressao[i] != expressao[j]){ 32 | printf("N", ); 33 | } 34 | } 35 | 36 | } 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Upsolving/NEPS Academy/Estruturas de Dados/Set/frequencia_na_aula.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | /* 7 | #ifndef ONLINE_JUDGE 8 | freopen("input.txt", "r", stdin); 9 | freopen("output.txt", "w", stdout); 10 | #endif 11 | */ 12 | 13 | int n, id; 14 | set alunos; 15 | 16 | scanf("%d", &n); 17 | 18 | while(n--){ 19 | scanf("%d", &id); 20 | alunos.insert(id); 21 | } 22 | 23 | printf("%d\n", alunos.size()); 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /Upsolving/NEPS Academy/Estruturas de Dados/Set/tacos_de_bilhar.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | /* 7 | #ifndef ONLINE_JUDGE 8 | freopen("input.txt", "r", stdin); 9 | freopen("output.txt", "w", stdout); 10 | #endif 11 | */ 12 | 13 | int n, taco, tacosProduzidos; 14 | set tacosEstoque; 15 | map contagem; 16 | 17 | scanf("%d", &n); 18 | 19 | tacosProduzidos = 0; 20 | 21 | while(n--){ 22 | scanf("%d", &taco); 23 | // Verifica se o taco não existe no estoque 24 | if(tacosEstoque.find(taco) != tacosEstoque.end()){ 25 | contagem[taco] = 1; 26 | tacosProduzidos += 2; 27 | tacosEstoque.insert(taco); 28 | }else{ 29 | if(contagem[taco] == 1){ 30 | contagem[taco] = 0; 31 | }else{ 32 | contagem[taco] = 1; 33 | tacosProduzidos += 2; 34 | } 35 | } 36 | 37 | } 38 | 39 | printf("%d\n", tacosProduzidos); 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Upsolving/NEPS Academy/Estruturas de Dados/Union Find/union-find-pd.cpp: -------------------------------------------------------------------------------- 1 | #define MAXN 100100 2 | 3 | using namespace std; 4 | 5 | pai[MAXN], peso[MAXN]; 6 | 7 | // funções do Union-Find otimizadas 8 | int find(int x){ 9 | 10 | if(pai[x]==x){ 11 | return x; 12 | } 13 | return pai[x]=find(pai[x]); 14 | } 15 | 16 | void join(int x, int y){ 17 | 18 | x=find(x); 19 | y=find(y); 20 | 21 | if(x==y){ 22 | return; 23 | } 24 | 25 | if(peso[x]peso[y]){ 29 | pai[y]=x; 30 | } 31 | 32 | if(peso[x]==peso[y]){ 33 | 34 | pai[x]=y; 35 | peso[y]++; 36 | } 37 | } -------------------------------------------------------------------------------- /Upsolving/NEPS Academy/Estruturas de Dados/Vector/vector_A_boraBora.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | 8 | return 0; 9 | } -------------------------------------------------------------------------------- /Upsolving/NEPS Academy/Estruturas de Dados/Vector/vector_A_fila.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | 8 | cin >> n; 9 | 10 | vector fila; 11 | 12 | for(int i = 0; i < n; i++){ 13 | int atual; 14 | cin >> atual; 15 | fila.push_back(atual); 16 | } 17 | 18 | int n2; 19 | map excluidos; 20 | 21 | cin >> n2; 22 | 23 | while(n2--){ 24 | int atual; 25 | cin >> atual; 26 | excluidos[atual] = true; 27 | } 28 | for(int i = 0; i < n; i++){ 29 | if(!excluidos[fila.at(i)]) 30 | if(i != n-1) 31 | cout << fila.at(i) << " "; 32 | else 33 | cout << fila.at(i) << endl; 34 | } 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Upsolving/NEPS Academy/Grafos/inputf.in: -------------------------------------------------------------------------------- 1 | 4 5 2 | 0 1 2 1 0 3 | 0 1 0 1 1 4 | 0 0 0 0 1 5 | 3 1 1 1 1 -------------------------------------------------------------------------------- /Upsolving/NEPS Academy/Grafos/outputf.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Upsolving/NEPS Academy/Grafos/outputf.in -------------------------------------------------------------------------------- /Upsolving/NEPS Academy/Programação Básica/funcoes_recursivas_A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int fib(int n){ 6 | if(n == 1 || n == 0){ 7 | return 1; 8 | }else 9 | return fib(n-1) + fib(n-2); 10 | 11 | } 12 | 13 | int main(){ 14 | int n; 15 | 16 | cin >> n; 17 | 18 | cout << fib(n) << endl; 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Upsolving/NEPS Academy/Programação Básica/inputf.in: -------------------------------------------------------------------------------- 1 | 10 10 2 | .......... 3 | .....###.. 4 | ....#####. 5 | .#...##... 6 | .......... 7 | .......##. 8 | .##....... 9 | ..##...... 10 | ..###..... 11 | ..#####... -------------------------------------------------------------------------------- /Upsolving/NEPS Academy/Programação Básica/outputf.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Upsolving/NEPS Academy/Programação Básica/outputf.in -------------------------------------------------------------------------------- /Upsolving/URI/1034.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | return 0; 8 | } -------------------------------------------------------------------------------- /Upsolving/URI/1153.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define S second 19 | #define PB push_back 20 | #define MP make_pair 21 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 22 | 23 | using namespace std; 24 | 25 | int fatorial(int n){ 26 | if(n == 1){ 27 | return 1; 28 | } 29 | return n*fatorial(n-1); 30 | } 31 | 32 | 33 | int main(){ 34 | #ifndef ONLINE_JUDGE 35 | 36 | // For getting input from input.txt file 37 | freopen("inputf.in", "r", stdin); 38 | 39 | // Printing the Output to output.txt file 40 | freopen("outputf.in", "w", stdout); 41 | #endif 42 | 43 | int n; 44 | 45 | cin >> n; 46 | 47 | cout << fatorial(n) << endl; 48 | 49 | return 0; 50 | } -------------------------------------------------------------------------------- /Upsolving/URI/1169.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define S second 19 | #define PB push_back 20 | #define MP make_pair 21 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 22 | 23 | using namespace std; 24 | 25 | int main(){ 26 | int n; 27 | 28 | cin >> n; 29 | 30 | forn(i, n){ 31 | int t; 32 | unsigned long long total; 33 | 34 | cin >> t; 35 | 36 | total = pow(2, t)/12000; 37 | 38 | cout << total << " kg" << endl; 39 | 40 | } 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /Upsolving/URI/1197.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define S second 19 | #define PB push_back 20 | #define MP make_pair 21 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 22 | 23 | using namespace std; 24 | 25 | int main(){ 26 | int n; 27 | 28 | cin >> n; 29 | 30 | forn(i, n){ 31 | int x,y; 32 | 33 | cin >> x >> y; 34 | 35 | int r = pow(3.0*x, 2) + pow(y*1.0, 2); 36 | int b = (2*pow(x*1.0, 2)) + pow(5.0*y, 2); 37 | int c = -100*x + pow(y*1.0, 3); 38 | 39 | if(r > b && r > c){ 40 | cout << "Rafael ganhou" << endl; 41 | }else if(b > r && b > c){ 42 | cout << "Beto ganhou" << endl; 43 | }else if(c > r && c > b){ 44 | cout << "Carlos ganhou" << endl; 45 | } 46 | } 47 | return 0; 48 | } -------------------------------------------------------------------------------- /Upsolving/URI/1199.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define S second 19 | #define PB push_back 20 | #define MP make_pair 21 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 22 | 23 | using namespace std; 24 | 25 | int main(){ 26 | while(true){ 27 | stringstream ss; 28 | string line; 29 | int n; 30 | 31 | cin >> line; 32 | 33 | // Verifica se é hex ou dec 34 | if(line[0] == '0' && line[1] == 'x'){ 35 | stringstream ss; 36 | 37 | ss << line; 38 | 39 | ss >> hex >> n; 40 | 41 | cout << dec << n << endl; 42 | }else{ 43 | n = stoi(line); 44 | 45 | if(n < 0) 46 | break; 47 | 48 | cout << "0x" << uppercase << hex << n << endl; 49 | } 50 | } 51 | 52 | return 0; 53 | } -------------------------------------------------------------------------------- /Upsolving/URI/1241.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define f first 18 | #define s second 19 | #define pb push_back 20 | #define mp make_pair 21 | #define l length() 22 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 23 | #define fornx(i, x, n) for ( int i = (x); i < (n); ++i ) 24 | 25 | using namespace std; 26 | 27 | int main(){ 28 | while(true){ 29 | char d; 30 | string n; 31 | cin >> d >> n; 32 | if(d == '0' && n == "0") break; 33 | 34 | n.erase(remove(n.begin(), n.end(), d), n.end()); 35 | 36 | int contador = 0; 37 | while(n[contador] == '0') 38 | contador++; 39 | 40 | n.erase(0, contador); 41 | 42 | if(n.empty()){ 43 | n = "0"; 44 | } 45 | 46 | cout << n << endl; 47 | } 48 | 49 | 50 | return 0; 51 | } -------------------------------------------------------------------------------- /Upsolving/URI/1247.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define S second 19 | #define PB push_back 20 | #define MP make_pair 21 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 22 | 23 | using namespace std; 24 | 25 | int main(){ 26 | 27 | 28 | // s = so + vt; 29 | 30 | /* 31 | 32 | L = ladrão G = guarda 33 | L G 34 | | / 35 | | / 36 | |/ 37 | Fronteira 38 | 39 | */ 40 | double d, vf, vg; 41 | while(cin >> d >> vf >> vg){ 42 | double hipotenusa = sqrt(d*d + 144); 43 | 44 | double sf = 12/vf; 45 | double sg = hipotenusa/vg; 46 | 47 | 48 | if(sg <= sf){ 49 | cout << "S" << endl; 50 | }else{ 51 | cout << "N" << endl; 52 | } 53 | } 54 | return 0; 55 | } -------------------------------------------------------------------------------- /Upsolving/URI/1259.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define S second 19 | #define PB push_back 20 | #define MP make_pair 21 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 22 | 23 | using namespace std; 24 | 25 | int main(){ 26 | vector pares,impares; 27 | int n; 28 | 29 | cin >> n; 30 | 31 | forn(i, n){ 32 | int aux; 33 | cin >> aux; 34 | if(aux%2 == 0) 35 | pares.push_back(aux); 36 | else 37 | impares.push_back(aux); 38 | } 39 | 40 | sort(pares.begin(), pares.end()); 41 | sort(impares.begin(), impares.end(), greater()); 42 | 43 | forn(i, pares.size()){ 44 | cout << pares.at(i) << endl; 45 | } 46 | forn(i, impares.size()){ 47 | cout << impares.at(i) << endl; 48 | } 49 | 50 | return 0; 51 | } -------------------------------------------------------------------------------- /Upsolving/URI/1323.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define S second 19 | #define PB push_back 20 | #define MP make_pair 21 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 22 | 23 | using namespace std; 24 | 25 | int main(){ 26 | while(true){ 27 | int n; 28 | 29 | cin >> n; 30 | if(n == 0) 31 | break; 32 | 33 | int total = (n*(n+1)*((2*n)+1))/6; 34 | 35 | cout << total << endl; 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Upsolving/URI/1429.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int fat(int n){ 6 | if(n == 1){ 7 | return 1; 8 | } 9 | return n * fat(n - 1); 10 | } 11 | 12 | int main(){ 13 | int n, n_digitos, ans; 14 | 15 | while(1){ 16 | cin >> n; 17 | 18 | if(n == 0){ 19 | break; 20 | } 21 | 22 | n_digitos = ceil(log10(n))+1; 23 | 24 | ans = 0; 25 | 26 | for(int i = 0; i < n_digitos; i++){ 27 | int digito = n%10; 28 | n = ceil(n/10); 29 | 30 | ans += digito * fat(i + 1); 31 | } 32 | 33 | cout << ans << endl; 34 | } 35 | 36 | 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Upsolving/URI/1436.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define S second 19 | #define PB push_back 20 | #define MP make_pair 21 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 22 | 23 | using namespace std; 24 | 25 | int main(){ 26 | int t; 27 | 28 | cin >> t; 29 | int contador = 1; 30 | while(t--){ 31 | int n; 32 | 33 | scanf("%d", &n); 34 | 35 | int idades[n]; 36 | 37 | forn(i, n){ 38 | cin >> idades[i]; 39 | } 40 | 41 | int pos = (n-1)/2; 42 | 43 | printf("Case %d: %d\n", contador, idades[pos]); 44 | contador++; 45 | } 46 | 47 | return 0; 48 | } -------------------------------------------------------------------------------- /Upsolving/URI/1534.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long ll; 4 | typedef unsigned long long ull; 5 | typedef long double ld; 6 | 7 | #define INF 0x3F3F3F3F 8 | #define LINF 0x3F3F3F3F3F3F3F3FLL 9 | #define DINF (double)1e+30 10 | #define EPS (double)1e-9 11 | #define PI (double)acos(-1.0) 12 | #define RAD(x) (double)(x*PI)/180.0 13 | #define PCT(x,y) (double)x*100.0/y 14 | 15 | using namespace std; 16 | 17 | void mostra_saida(int tamanho){ 18 | int k = tamanho-1; 19 | for(int i = 0; i < tamanho; i++){ 20 | for(int j = 0; j < tamanho; j++){ 21 | if(j != i && j != k){ 22 | cout << "3"; 23 | }else if(j == k){ 24 | cout << "2"; 25 | }else if(j == i){ 26 | cout << "1"; 27 | }else{ 28 | cout << "2"; 29 | } 30 | } 31 | k--; 32 | cout << "\n"; 33 | } 34 | } 35 | 36 | int main(){ 37 | int entrada; 38 | 39 | while (true) { 40 | cin >> entrada; 41 | if (!cin) 42 | break; 43 | mostra_saida(entrada); 44 | } 45 | } -------------------------------------------------------------------------------- /Upsolving/URI/1541.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long ll; 4 | typedef unsigned long long ull; 5 | typedef long double ld; 6 | 7 | #define INF 0x3F3F3F3F 8 | #define LINF 0x3F3F3F3F3F3F3F3FLL 9 | #define DINF (double)1e+30 10 | #define EPS (double)1e-9 11 | #define PI (double)acos(-1.0) 12 | #define RAD(x) (double)(x*PI)/180.0 13 | #define PCT(x,y) (double)x*100.0/y 14 | 15 | using namespace std; 16 | 17 | int calculaLado(double porcentagem, int area){ 18 | return (int)sqrt(area/porcentagem); 19 | } 20 | 21 | int main(){ 22 | int a, b, c; 23 | 24 | while (true) { 25 | cin >> a; 26 | if (a == 0) 27 | break; 28 | cin >> b; 29 | cin >> c; 30 | double porcentagem = c/100.0; 31 | int area = a*b; 32 | cout << calculaLado(porcentagem, area) << "\n"; 33 | } 34 | } -------------------------------------------------------------------------------- /Upsolving/URI/1566.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define S second 19 | #define PB push_back 20 | #define MP make_pair 21 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 22 | 23 | using namespace std; 24 | 25 | int main(){ 26 | 27 | int nc; 28 | vector alturas; 29 | cin >> nc; 30 | 31 | forn(i, nc){ 32 | int n; 33 | cin >> n; 34 | alturas.resize(n); 35 | 36 | forn(j, n){ 37 | scanf("%d", &alturas[j]); 38 | } 39 | 40 | sort(alturas.begin(), alturas.end()); 41 | 42 | printf("%d", alturas[0]); 43 | for(int j = 1; j < n; j++){ 44 | printf(" %d", alturas[j]); 45 | } 46 | printf("\n"); 47 | } 48 | 49 | 50 | return 0; 51 | } -------------------------------------------------------------------------------- /Upsolving/URI/1789.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | while(true){ 8 | int n; 9 | int maior = 0; 10 | cin >> n; 11 | if(!cin) break; 12 | for(int i = 0; i < n; i++){ 13 | int temp; 14 | cin >> temp; 15 | if(temp > maior){ 16 | maior = temp; 17 | } 18 | } 19 | if(maior < 10){ 20 | cout << "1" << endl; 21 | }else if(maior >= 20){ 22 | cout << "3" << endl; 23 | }else{ 24 | cout << "2" << endl; 25 | } 26 | } 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Upsolving/URI/1795.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | long long n; 7 | 8 | cin >> n; 9 | 10 | if(n == 0){ 11 | cout << "1" << endl; 12 | 13 | return 0; 14 | } 15 | 16 | long long matriz[n+1][(2*n)+1]; 17 | 18 | for(int i = 0; i < n+1; i++){ 19 | for(int j = 0; j < (2*n)+1; j++){ 20 | matriz[i][j] = 0; 21 | } 22 | } 23 | int inicioLinha, fimLinha; 24 | 25 | matriz[0][n] = 1; 26 | inicioLinha = n-1; 27 | fimLinha = n+1; 28 | long long contador = 0; 29 | 30 | for(int i = 1; i <= n; i++){ 31 | contador = 0; 32 | for(int j = inicioLinha; j <= fimLinha; j++){ 33 | if(j == inicioLinha || j == fimLinha){ 34 | matriz[i][j] = 1; 35 | }else{ 36 | matriz[i][j] = matriz[i-1][j] + matriz[i-1][j-1] + matriz[i-1][j+1]; 37 | } 38 | contador += matriz[i][j]; 39 | } 40 | inicioLinha--; 41 | fimLinha++; 42 | } 43 | /* 44 | for(int i = 0; i < n+1; i++){ 45 | 46 | for(int j = 0; j < (2*n)+1; j++){ 47 | cout << matriz[i][j] << " "; 48 | } 49 | cout << endl; 50 | } 51 | */ 52 | 53 | cout << contador << endl; 54 | 55 | return 0; 56 | } -------------------------------------------------------------------------------- /Upsolving/URI/1805.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define S second 19 | #define PB push_back 20 | #define MP make_pair 21 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 22 | 23 | using namespace std; 24 | 25 | int main(){ 26 | unsigned long long i, s; 27 | 28 | scanf("%llu %llu", &i, &s); 29 | 30 | long long soma; 31 | 32 | soma = (i + s) * (s - i + 1) / 2; 33 | 34 | printf("%llu\n", soma); 35 | //cout << soma << endl; 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Upsolving/URI/1828.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | int n; 8 | string a, b; 9 | 10 | cin >> n; 11 | cin.ignore(); 12 | 13 | for(int i = 1; i <= n; i++){ 14 | cin >> a >> b; 15 | if(a == b) { 16 | cout << "Caso #"<< i << ": De novo!" << endl; 17 | }else if(a == "tesoura" && b == "papel" || a == "papel" && b == "pedra" || a == "pedra" && b == "lagarto" || a == "lagarto" && b == "Spock" || a == "Spock" && b == "tesoura" || a == "tesoura" && b == "lagarto" || a == "lagarto" && b == "papel" || a == "papel" && b == "Spock" || a == "Spock" && b == "pedra" || a == "pedra" && b == "tesoura"){ 18 | cout << "Caso #"<< i << ": Bazinga!" << endl; 19 | }else{ 20 | cout << "Caso #"<< i << ": Raj trapaceou!" << endl; 21 | } 22 | } 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Upsolving/URI/1837.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long ll; 4 | typedef unsigned long long ull; 5 | typedef long double ld; 6 | 7 | #define INF 0x3F3F3F3F 8 | #define LINF 0x3F3F3F3F3F3F3F3FLL 9 | #define DINF (double)1e+30 10 | #define EPS (double)1e-9 11 | #define PI (double)acos(-1.0) 12 | #define RAD(x) (double)(x*PI)/180.0 13 | #define PCT(x,y) (double)x*100.0/y 14 | 15 | using namespace std; 16 | 17 | int main() 18 | { 19 | int a, b, c; 20 | int q, r; 21 | 22 | cin >> a >> b; 23 | 24 | q = a/b; 25 | r = a%b; 26 | 27 | if(r < 0){ 28 | int c,d; 29 | c = (a < 0) ? a*-1 : a; 30 | d = (b < 0) ? b*-1 : b; 31 | 32 | q = (c+d)/d; 33 | r = (c - (q * d))*-1; 34 | 35 | q = (a*b > 0) ? q : q*-1; 36 | } 37 | 38 | cout << q << " " << r << endl; 39 | 40 | } -------------------------------------------------------------------------------- /Upsolving/URI/1848.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 4 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 5 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 6 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 7 | 8 | using namespace std; 9 | 10 | int calcNumero(string s){ 11 | int n = 0, i; 12 | string::iterator it; 13 | 14 | for ( it = (s.end()-1), i = 0; it >= s.begin(); it--, i++){ 15 | if(*it == '*'){ 16 | n += pow(2, i); 17 | } 18 | } 19 | return n; 20 | } 21 | 22 | int main(){ 23 | string a; 24 | int total = 0; 25 | 26 | while(cin >> a){ 27 | if(a == "caw"){ 28 | cin >> a; 29 | cout << total << endl; 30 | total = 0; 31 | }else{ 32 | total+=calcNumero(a); 33 | } 34 | 35 | 36 | } 37 | 38 | 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Upsolving/URI/1858.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int n, menor, pos; 16 | vector p; 17 | 18 | menor = INF; 19 | pos = 0; 20 | 21 | cin >> n; 22 | 23 | forn(i, n){ 24 | int temp; 25 | cin >> temp; 26 | p.push_back(temp); 27 | if(p[i] < menor){ 28 | menor = p[i]; 29 | pos = i+1; 30 | } 31 | } 32 | 33 | cout << pos << endl; 34 | 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Upsolving/URI/1864.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int n; 16 | 17 | string frase {"LIFE IS NOT A PROBLEM TO BE SOLVED"}; 18 | 19 | cin >> n; 20 | 21 | forn(i, n){ 22 | cout << frase[i]; 23 | } 24 | 25 | cout << endl; 26 | 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Upsolving/URI/1865.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int n; 16 | string p; 17 | 18 | cin >> n; 19 | 20 | forn(i, n){ 21 | cin >> p; 22 | if(p == "Thor") cout << "Y" << endl; 23 | else cout << "N" << endl; 24 | cin >> p; 25 | } 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Upsolving/URI/1871.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define ll long long int 6 | 7 | int main(){ 8 | ll n1, n2; 9 | stringstream ss; 10 | string resultado; 11 | 12 | while(true){ 13 | scanf("%lld %lld", &n1, &n2); 14 | 15 | if(n1 == n2 && n1 == 0) 16 | break; 17 | 18 | //printf("%lld %lld\n", n1, n2); 19 | 20 | ss << (n1+n2); 21 | resultado = ss.str(); 22 | 23 | resultado.erase(remove(resultado.begin(), resultado.end(), '0'), resultado.end()); 24 | cout << resultado << "\n"; 25 | 26 | ss.str(std::string()); 27 | } 28 | 29 | 30 | 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Upsolving/URI/1893.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int n, pos_maior = 0; 16 | double maior = 0.0; 17 | 18 | cin >> n; 19 | 20 | int ra[n]; 21 | double notas[n]; 22 | 23 | forn(i, n){ 24 | cin >> ra[i] >> notas[i]; 25 | if(notas[i] > maior){ 26 | maior = notas[i]; 27 | pos_maior = i; 28 | } 29 | } 30 | if(maior >= 8){ 31 | cout << ra[pos_maior] << endl; 32 | }else{ 33 | cout << "Minimum note not reached" << endl; 34 | } 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Upsolving/URI/1921.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int n; 16 | vector c; 17 | 18 | forn(i, n){ 19 | string temp; 20 | cin >> temp; 21 | c.push_back(temp); 22 | } 23 | 24 | cout << "Ciencia da Computacao" << endl; 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Upsolving/URI/1929.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int a,b,c,d; 16 | 17 | cin >> a >> b >> c >> d; 18 | 19 | // a,b,c 20 | if((a-b) < c && (a+b) > c && (a-c) < b && (a+c) > b && (a-b) < c && (a+b) > c){ 21 | cout << "S" << endl; 22 | // a,b,d 23 | }else if((a-b) < d && (a+b) > d && (a-d) < b && (a+d) > b && (a-b) < d && (a+b) > d){ 24 | cout << "S" << endl; 25 | // d,b,c 26 | }else if((d-b) < c && (d+b) > c && (d-c) < b && (d+c) > b && (d-b) < c && (d+b) > c){ 27 | cout << "S" << endl; 28 | // a,d,c 29 | }else if((a-d) < c && (a+d) > c && (a-c) < d && (a+c) > d && (a-d) < c && (a+d) > c){ 30 | cout << "S" << endl; 31 | }else{ 32 | cout << "N" << endl; 33 | } 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Upsolving/URI/1930.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int t1,t2,t3,t4; 16 | int n; 17 | 18 | cin >> t1 >> t2 >> t3 >> t4; 19 | 20 | n = (t1-1)+(t2-1)+(t3-1)+t4; 21 | 22 | cout << n << endl; 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Upsolving/URI/1933.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int a, b; 16 | 17 | cin >> a >> b; 18 | 19 | if(a != b){ 20 | if(a > b){ 21 | cout << a << endl; 22 | }else{ 23 | cout << b << endl; 24 | } 25 | }else{ 26 | cout << a << endl; 27 | } 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Upsolving/URI/1957.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int v; 16 | 17 | cin >> v; 18 | 19 | cout << hex << uppercase << v << endl; 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Upsolving/URI/1958.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | long double x; 16 | string line; 17 | 18 | cout << scientific << setprecision(4) << uppercase; 19 | 20 | cin >> line; 21 | if(line[0] != '-'){ 22 | cout << "+"; 23 | } 24 | 25 | stringstream ss(line); 26 | 27 | ss >> x; 28 | 29 | cout << x << endl; 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Upsolving/URI/1959.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | long long int n, l, p; 16 | 17 | cin >> n >> l; 18 | 19 | p = n*l; 20 | 21 | cout << p << endl; 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Upsolving/URI/1961.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int p, n, prox, atual; 16 | bool possivel = true; 17 | 18 | cin >> p >> n; 19 | 20 | forn(i, n){ 21 | cin >> prox; 22 | if(i == 0){ 23 | atual = prox; 24 | continue; 25 | } 26 | if(prox < atual){ 27 | if(prox < (atual-p)){ 28 | possivel = false; 29 | break; 30 | } 31 | }else{ 32 | if(prox > (atual+p)){ 33 | possivel = false; 34 | break; 35 | } 36 | } 37 | atual = prox; 38 | } 39 | 40 | if(possivel){ 41 | cout << "YOU WIN" << endl; 42 | }else{ 43 | cout << "GAME OVER" << endl; 44 | } 45 | 46 | return 0; 47 | } -------------------------------------------------------------------------------- /Upsolving/URI/1962.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int n, aux, temp; 16 | 17 | cin >> n; 18 | 19 | forn(i, n){ 20 | cin >> aux; 21 | 22 | temp = 2015-aux; 23 | 24 | if(temp <= 0){ 25 | temp*=-1; 26 | cout << temp+1 << " A.C." << endl; 27 | }else{ 28 | cout << temp << " D.C." << endl; 29 | } 30 | } 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Upsolving/URI/1963.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | double a,b, p; 16 | 17 | cin >> a >> b; 18 | 19 | p = ((b/a)-1)*100; 20 | 21 | cout << fixed << setprecision(2) << p << "%" << endl; 22 | 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Upsolving/URI/1973.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int n; 16 | 17 | cin >> n; 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Upsolving/URI/1983.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); --i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int n, maior = 0, pos_maior = 0; 16 | 17 | cin >> n; 18 | 19 | int ra[n], notas[n]; 20 | 21 | forn(i, n){ 22 | cin >> ra[i] >> notas[i]; 23 | if(notas[i] > maior){ 24 | maior = notas[i]; 25 | pos_maior = i; 26 | } 27 | } 28 | if(maior >=){ 29 | cout << ra[pos_maior] << endl; 30 | }else{ 31 | cout << "Minimum note not reached" << endl; 32 | } 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Upsolving/URI/1984.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long ll; 4 | typedef unsigned long long ull; 5 | typedef long double ld; 6 | 7 | #define INF 0x3F3F3F3F 8 | #define LINF 0x3F3F3F3F3F3F3F3FLL 9 | #define DINF (double)1e+30 10 | #define EPS (double)1e-9 11 | #define PI (double)acos(-1.0) 12 | #define RAD(x) (double)(x*PI)/180.0 13 | #define PCT(x,y) (double)x*100.0/y 14 | 15 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 16 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 17 | 18 | using namespace std; 19 | 20 | int main(){ 21 | int n; 22 | 23 | cin >> n; 24 | 25 | int p[n]; 26 | double q[n], total = 0; 27 | 28 | forn(i, n){ 29 | cin >> p[i] >> q[i]; 30 | if(p[i] == 1001){ 31 | total+=q[i]*1.5; 32 | }else if(p[i] == 1002){ 33 | total+=q[i]*2.5; 34 | }else if(p[i] == 1003){ 35 | total+=q[i]*3.5; 36 | }else if(p[i] == 1004){ 37 | total+=q[i]*4.5; 38 | }else { 39 | total+=q[i]*5.5; 40 | } 41 | } 42 | cout << fixed << setprecision(2) << total << endl; 43 | return 0; 44 | } -------------------------------------------------------------------------------- /Upsolving/URI/2003.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long ll; 4 | typedef unsigned long long ull; 5 | typedef long double ld; 6 | 7 | #define INF 0x3F3F3F3F 8 | #define LINF 0x3F3F3F3F3F3F3F3FLL 9 | #define DINF (double)1e+30 10 | #define EPS (double)1e-9 11 | #define PI (double)acos(-1.0) 12 | #define RAD(x) (double)(x*PI)/180.0 13 | #define PCT(x,y) (double)x*100.0/y 14 | 15 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 16 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 17 | 18 | using namespace std; 19 | 20 | int main(){ 21 | int n. contador, contador_casos; 22 | while(true){ 23 | contador = 1; 24 | cout << "0 "; 25 | cin >> n; 26 | if(!cin) break; 27 | forn(i, n){ 28 | int temp; 29 | cin >> temp 30 | forn(j, temp){ 31 | cout << temp << " "; 32 | } 33 | } 34 | } 35 | 36 | cout << contador << endl; 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Upsolving/URI/2006.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigoAMF/competitive-programming/06b38197a042bfbd27b20f707493e0a19fda7234/Upsolving/URI/2006.cpp -------------------------------------------------------------------------------- /Upsolving/URI/2025.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define ll long long int 6 | 7 | int main(){ 8 | int n, contador; 9 | string linha, substring; 10 | substring = "oulupukk"; 11 | 12 | scanf("%d ", &n); 13 | 14 | while(n--){ 15 | getline(cin, linha); 16 | 17 | // oulupukk(8) 18 | for(int i = 0; i < linha.length()-8; i++){ 19 | if(linha[i] == 'o'){ 20 | contador = 1; 21 | for(int j = 1; j < 8; j++){ 22 | if(linha[i+j] == substring[j]) 23 | contador++; 24 | else 25 | break; 26 | } 27 | 28 | if(contador == 8){ 29 | //cout << i-1 << " " << i+8 << endl; 30 | linha[i-1] = 'J'; 31 | linha[i+8] = 'i'; 32 | } 33 | } 34 | } 35 | 36 | cout << linha << endl; 37 | } 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Upsolving/URI/2029.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long ll; 4 | typedef unsigned long long ull; 5 | typedef long double ld; 6 | 7 | #define INF 0x3F3F3F3F 8 | #define LINF 0x3F3F3F3F3F3F3F3FLL 9 | #define DINF (double)1e+30 10 | #define EPS (double)1e-9 11 | #define RAD(x) (double)(x*PI)/180.0 12 | #define PCT(x,y) (double)x*100.0/y 13 | 14 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 15 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 16 | 17 | using namespace std; 18 | 19 | int main(){ 20 | double v, d, pi, r; 21 | pi = 3.14; 22 | 23 | 24 | while(true){ 25 | double altura, area; 26 | 27 | cin >> v >> d; 28 | if(!cin) break; 29 | r = d/2; 30 | 31 | altura = v/(pi*(pow(r, 2))); 32 | area = pi*r*r; 33 | 34 | cout << fixed << setprecision(2); 35 | cout << "ALTURA = " << altura << endl; 36 | cout << "AREA = " << area << endl; 37 | } 38 | 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Upsolving/URI/2057.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long ll; 4 | typedef unsigned long long ull; 5 | typedef long double ld; 6 | 7 | #define INF 0x3F3F3F3F 8 | #define LINF 0x3F3F3F3F3F3F3F3FLL 9 | #define DINF (double)1e+30 10 | #define EPS (double)1e-9 11 | #define RAD(x) (double)(x*PI)/180.0 12 | #define PCT(x,y) (double)x*100.0/y 13 | 14 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 15 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 16 | 17 | using namespace std; 18 | 19 | int main(){ 20 | int s,t,f,h; 21 | 22 | cin >> s >> t >> f; 23 | 24 | h = s+t+f; 25 | 26 | if(h >= 24){ 27 | h-=24; 28 | } 29 | if(h < 0){ 30 | h+=24; 31 | } 32 | 33 | cout << h << endl; 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Upsolving/URI/2061.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long ll; 4 | typedef unsigned long long ull; 5 | typedef long double ld; 6 | 7 | #define INF 0x3F3F3F3F 8 | #define LINF 0x3F3F3F3F3F3F3F3FLL 9 | #define DINF (double)1e+30 10 | #define EPS (double)1e-9 11 | #define RAD(x) (double)(x*PI)/180.0 12 | #define PCT(x,y) (double)x*100.0/y 13 | 14 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 15 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 16 | 17 | using namespace std; 18 | 19 | int main(){ 20 | int a, n; 21 | string aux; 22 | 23 | cin >> a >> n; 24 | 25 | forn(i, n){ 26 | cin >> aux; 27 | if(aux == "fechou"){ 28 | a++; 29 | }else{ 30 | a--; 31 | } 32 | } 33 | 34 | cout << a << endl; 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Upsolving/URI/2062.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | int main() { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | 10 | int n; 11 | 12 | cin >> n; 13 | cin.ignore(); 14 | 15 | string palavra; 16 | 17 | for(int i = 0; i < n; i++){ 18 | cin >> palavra; 19 | if(palavra.length() == 3){ 20 | if(palavra[0] == 'U' && palavra[1] == 'R'){ 21 | cout << "URI"; 22 | }else if(palavra[0] == 'O' && palavra[1] == 'B'){ 23 | cout << "OBI"; 24 | }else{ 25 | cout << palavra; 26 | } 27 | }else{ 28 | cout << palavra; 29 | } 30 | if(i < (n-1)){ 31 | cout << " "; 32 | }else{ 33 | cout << "\n"; 34 | } 35 | } 36 | 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Upsolving/URI/2137.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | int n, x; 7 | vector valores; 8 | 9 | while(scanf("%d", &n) != EOF){ 10 | valores.clear(); 11 | while(n--){ 12 | scanf("%d", &x); 13 | valores.push_back(x); 14 | } 15 | sort(valores.begin(), valores.end()); 16 | for(int i = 0; i < valores.size(); ++i){ 17 | printf("%04d\n", valores.at(i)); 18 | } 19 | } 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Upsolving/URI/2150.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | 7 | int main() { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | 11 | string vogais, texto; 12 | ll quantidadeVogais; 13 | 14 | while(1){ 15 | quantidadeVogais = 0; 16 | getline(cin, vogais); 17 | if(!cin) break; 18 | getline(cin, texto); 19 | if(!cin) break; 20 | 21 | for(int i = 0; i < (int)texto.length(); i++){ 22 | for(int j = 0; j < (int)vogais.length(); j++){ 23 | if(texto[i] == vogais[j]){ 24 | quantidadeVogais++; 25 | break; 26 | } 27 | } 28 | } 29 | 30 | cout << quantidadeVogais << "\n"; 31 | } 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Upsolving/URI/2162.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long ll; 4 | typedef unsigned long long ull; 5 | typedef long double ld; 6 | 7 | #define INF 0x3F3F3F3F 8 | #define LINF 0x3F3F3F3F3F3F3F3FLL 9 | #define DINF (double)1e+30 10 | #define EPS (double)1e-9 11 | #define RAD(x) (double)(x*PI)/180.0 12 | #define PCT(x,y) (double)x*100.0/y 13 | 14 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 15 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 16 | 17 | using namespace std; 18 | 19 | int main(){ 20 | int n, m, troco; 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Upsolving/URI/2165.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | string tweet; 16 | 17 | getline(cin, tweet); 18 | 19 | if(tweet.length() > 140){ 20 | cout << "MUTE" << endl; 21 | }else{ 22 | cout << "TWEET" << endl; 23 | } 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /Upsolving/URI/2166.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int n; 16 | long double resultado = 0.0; 17 | 18 | cin >> n; 19 | 20 | forn(i, n){ 21 | if(i == 0){ 22 | resultado=1.0/2.0; 23 | }else{ 24 | resultado=1.0/(2.0+resultado); 25 | } 26 | } 27 | 28 | resultado+=1.00; 29 | 30 | cout << fixed << setprecision(10) << resultado << endl;; 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Upsolving/URI/2167.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int atual, anterior, n, pos = 0; 16 | 17 | cin >> n; 18 | 19 | forn(i, n){ 20 | cin >> atual; 21 | if(i != 0){ 22 | if(atual < anterior){ 23 | pos = i+1; 24 | break; 25 | } 26 | } 27 | anterior = atual; 28 | } 29 | 30 | cout << pos << endl; 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Upsolving/URI/2172.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | long long int x, m, resultado; 16 | 17 | while(true){ 18 | cin >> x >> m; 19 | if(x == m && x == 0) break; 20 | resultado = x*m; 21 | 22 | cout << resultado << endl; 23 | } 24 | 25 | 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Upsolving/URI/2176.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | string mensagem; 16 | int contador = 0; 17 | 18 | cin >> mensagem; 19 | 20 | forn(i, mensagem.length()){ 21 | if(mensagem[i] == '1') 22 | contador++; 23 | } 24 | 25 | if(contador%2 == 0){ 26 | contador = 0; 27 | }else{ 28 | contador = 1; 29 | } 30 | 31 | cout << mensagem << contador << endl; 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Upsolving/URI/2203.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | double xf, yf, xi, yi, vi, ru, rc; 16 | double range, distancia; 17 | 18 | while(true){ 19 | cin >> xf >> yf >> xi >> yi >> vi >> ru >> rc; 20 | if(!cin) break; 21 | 22 | distancia = pow((xi-xf), 2.0); 23 | distancia = distancia+pow((yi-yf), 2.0); 24 | distancia = sqrt(distancia); 25 | distancia += vi*1.5; 26 | 27 | range = ru+rc; 28 | 29 | if(distancia < range){ 30 | cout << "Y" << endl; 31 | }else{ 32 | cout << "N" << endl; 33 | } 34 | } 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Upsolving/URI/2221.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int n; 16 | 17 | int b, a1, d1, l1, a2, d2, l2; 18 | double vg1, vg2; 19 | 20 | while(true){ 21 | cin >> n; 22 | if(!cin) break; 23 | forn(i, n){ 24 | cin >> b; 25 | cin >> a1 >> d1 >> l1; 26 | cin >> a2 >> d2 >> l2; 27 | 28 | vg1 = (a1+d1)/2.0; 29 | vg2 = (a2+d2)/2.0; 30 | if(l1%2 == 0) 31 | vg1+=b; 32 | if(l2%2 == 0) 33 | vg2+=b; 34 | if(vg1 > vg2){ 35 | cout << "Dabriel" << endl; 36 | }else if(vg1 < vg2){ 37 | cout << "Guarte" << endl; 38 | }else{ 39 | cout << "Empate" << endl; 40 | } 41 | } 42 | } 43 | 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /Upsolving/URI/2234.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | double h, p; 16 | double resultado; 17 | 18 | cin >> h >> p; 19 | 20 | resultado = h/p; 21 | 22 | cout << fixed << setprecision(2) << resultado << endl; 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Upsolving/URI/2235.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int a, b, c; 16 | 17 | cin >> a >> b >> c; 18 | 19 | if(a == b || b == c || a == c || (a+b) == c || (a+c) == b || (b+c) == a) 20 | cout << "S" << endl; 21 | else 22 | cout << "N" << endl; 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Upsolving/URI/2334.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | string valor; 16 | unsigned long long int n; 17 | 18 | 19 | while(true){ 20 | cin >> valor; 21 | 22 | if(valor[0] == '-') break; 23 | else 24 | n = stoull(valor, 0, 10); 25 | 26 | if(n > 0) 27 | n -= 1; 28 | else 29 | n = 0; 30 | 31 | cout << n << endl; 32 | } 33 | 34 | 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Upsolving/URI/2484.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | string palavra; 7 | 8 | while(cin >> palavra){ 9 | for(int i = 0; i < palavra.length(); i++){ 10 | cout << palavra << endl; 11 | palavra.erase(palavra.length()-1, palavra.length()); 12 | } 13 | cout << endl; 14 | } 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Upsolving/URI/2510.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int n; 16 | string v; 17 | 18 | cin >> n; 19 | 20 | forn(i, n){ 21 | cin >> v; 22 | 23 | cout << "Y" << endl; 24 | 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Upsolving/URI/2520.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int n, m, x1, y1, x2, y2; 16 | 17 | while(true){ 18 | int distancia; 19 | x1 = x2 = y1 = y2 = 0; 20 | cin >> n >> m; 21 | if(!cin) break; 22 | 23 | forn(i, n){ 24 | forn(j, m){ 25 | int aux; 26 | cin >> aux; 27 | if(aux == 1){ 28 | x1 = i; 29 | y1 = j; 30 | } 31 | if(aux == 2){ 32 | x2 = i; 33 | y2 = j; 34 | } 35 | } 36 | } 37 | int resultado = 0; 38 | 39 | resultado = abs(x2-x1) + abs(y2-y1); 40 | 41 | cout << resultado << endl; 42 | 43 | } 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /Upsolving/URI/2523.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | string letras; 16 | int n; 17 | int aux; 18 | while(true){ 19 | cin >> letras; 20 | if(!cin) break; 21 | cin >> n; 22 | forn(i, n){ 23 | cin >> aux; 24 | cout << letras[aux-1]; 25 | } 26 | cout << endl; 27 | } 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Upsolving/URI/2533.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int m; 16 | double ira, ira2; 17 | double n,c; 18 | while(true){ 19 | cin >> m; 20 | if(!cin) break; 21 | 22 | ira = ira2 = 0; 23 | 24 | forn(i, m){ 25 | cin >> n >> c; 26 | ira += (n*c); 27 | ira2 += (c*100); 28 | } 29 | 30 | cout << fixed << setprecision(4) << (ira/ira2) << endl; 31 | } 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Upsolving/URI/2534.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int n, q; 16 | 17 | while(true){ 18 | vector p; 19 | 20 | cin >> n >> q; 21 | if(!cin) break; 22 | 23 | forn(i, n){ 24 | int aux; 25 | cin >> aux; 26 | p.push_back(aux); 27 | } 28 | sort(p.begin(), p.end(), greater()); 29 | //sort(p.begin(), p.end()); 30 | forn(i, q){ 31 | int aux; 32 | cin >> aux; 33 | 34 | cout << p[aux-1] << endl; 35 | } 36 | } 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Upsolving/URI/2538.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int getNumeroPokemonsNoIntervalo(int pc, vector pokemonsNoGinasio){ 6 | return 1; 7 | } 8 | 9 | 10 | int main(){ 11 | /* 12 | ip = intervalo de poder 13 | m = tentativas de colocar pokemon 14 | */ 15 | int ip, m; 16 | 17 | // pc = pontos de combate 18 | // na = número de ataques 19 | int pc, na; 20 | 21 | vector pokemonsNoGinasio; 22 | int numeroPokemonsNoIntervalo; 23 | 24 | scanf("%d %d", &ip, &m); 25 | 26 | for(int i = 0; i < m; i++){ 27 | scanf("%d %d", &pc, &na); 28 | 29 | numeroPokemonsNoIntervalo = getNumeroPokemonsNoIntervalo(pc, pokemonsNoGinasio); 30 | if(numeroPokemonsNoIntervalo <= na){ 31 | pokemonsNoGinasio.push_back(pc); 32 | } 33 | // se numeroPokemonsNoIntervalo <= na, coloca no ginásio 34 | } 35 | 36 | printf("%d\n", pokemonsNoGinasio.size()); 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Upsolving/URI/2540.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int n; 16 | 17 | while(true){ 18 | int resultado = 0; 19 | 20 | cin >> n; 21 | if(!cin) break; 22 | 23 | forn(i, n){ 24 | int aux; 25 | cin >> aux; 26 | if(aux == 1) 27 | resultado++; 28 | } 29 | if(resultado >= ((2.0*n)/3.0)){ 30 | cout << "impeachment" << endl; 31 | }else{ 32 | cout << "acusacao arquivada" << endl; 33 | } 34 | } 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Upsolving/URI/2542.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define INF 0x3F3F3F3F 4 | #define LINF 0x3F3F3F3F3F3F3F3FLL 5 | #define DINF (double)1e+30 6 | 7 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 8 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 9 | #define forr(i, a, b) for ( int i = (a); i <= (b); ++i ) 10 | #define ford(i, a, b) for ( int i = (a); i >= (b); −−i ) 11 | 12 | using namespace std; 13 | 14 | int main(){ 15 | int n, m, l; 16 | while(true){ 17 | cin >> n; 18 | if(!cin) break; 19 | 20 | cin >> m >> l; 21 | } 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Upsolving/URI/2543.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long ll; 4 | typedef unsigned long long ull; 5 | typedef long double ld; 6 | 7 | #define INF 0x3F3F3F3F 8 | #define LINF 0x3F3F3F3F3F3F3F3FLL 9 | #define DINF (double)1e+30 10 | #define EPS (double)1e-9 11 | #define RAD(x) (double)(x*PI)/180.0 12 | #define PCT(x,y) (double)x*100.0/y 13 | 14 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 15 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 16 | 17 | using namespace std; 18 | 19 | int main(){ 20 | int n, id; 21 | 22 | while(true){ 23 | cin >> n >> id; 24 | if(!cin) break; 25 | int contador = 0; 26 | 27 | forn(i, n){ 28 | int idAux, jAux; 29 | cin >> idAux >> jAux; 30 | if(idAux == id && jAux == 0){ 31 | contador++; 32 | } 33 | } 34 | cout << contador << endl; 35 | } 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Upsolving/URI/2544.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long ll; 4 | typedef unsigned long long ull; 5 | typedef long double ld; 6 | 7 | #define INF 0x3F3F3F3F 8 | #define LINF 0x3F3F3F3F3F3F3F3FLL 9 | #define DINF (double)1e+30 10 | #define EPS (double)1e-9 11 | #define RAD(x) (double)(x*PI)/180.0 12 | #define PCT(x,y) (double)x*100.0/y 13 | 14 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 15 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 16 | 17 | using namespace std; 18 | 19 | int main(){ 20 | long long int n; 21 | 22 | while(true){ 23 | cin >> n; 24 | if(!cin) break; 25 | int contador = 0; 26 | int copias = 1; 27 | while(true){ 28 | if(copias == n) break; 29 | copias*=2; 30 | contador++; 31 | } 32 | if(n == 1){ 33 | cout << "0" << endl; 34 | }else{ 35 | cout << contador << endl; 36 | } 37 | } 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Upsolving/URI/2547.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long ll; 4 | typedef unsigned long long ull; 5 | typedef long double ld; 6 | 7 | #define INF 0x3F3F3F3F 8 | #define LINF 0x3F3F3F3F3F3F3F3FLL 9 | #define DINF (double)1e+30 10 | #define EPS (double)1e-9 11 | #define RAD(x) (double)(x*PI)/180.0 12 | #define PCT(x,y) (double)x*100.0/y 13 | 14 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 15 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 16 | 17 | using namespace std; 18 | 19 | int main(){ 20 | int n, min, max; 21 | 22 | while(true){ 23 | cin >> n >> min >> max; 24 | if(!cin) break; 25 | int contador = 0; 26 | 27 | forn(i, n){ 28 | int aux; 29 | cin >> aux; 30 | if(aux >= min && aux <= max){ 31 | contador++; 32 | } 33 | } 34 | cout << contador << endl; 35 | } 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Upsolving/URI/2551.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long ll; 4 | typedef unsigned long long ull; 5 | typedef long double ld; 6 | 7 | #define INF 0x3F3F3F3F 8 | #define LINF 0x3F3F3F3F3F3F3F3FLL 9 | #define DINF (double)1e+30 10 | #define EPS (double)1e-9 11 | #define RAD(x) (double)(x*PI)/180.0 12 | #define PCT(x,y) (double)x*100.0/y 13 | 14 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 15 | #define forxn(i, x, n) for ( int i = (x); i < (n); ++i ) 16 | 17 | using namespace std; 18 | 19 | int main(){ 20 | int n; 21 | 22 | while(true){ 23 | cout << "1" << endl; 24 | cin >> n; 25 | if(!cin) break; 26 | double dia; 27 | double recorde; 28 | 29 | forn(i, n){ 30 | double t, d; 31 | cin >> t >> d; 32 | if(i == 0){ 33 | dia = i+1; 34 | recorde = d/t; 35 | }else{ 36 | if((d/t) > recorde){ 37 | dia = i+1; 38 | recorde = d/t; 39 | } 40 | } 41 | } 42 | cout << dia << endl; 43 | } 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /Upsolving/URI/2590.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | //freopen("inputf.in", "r", stdin); 7 | //freopen("outputf.in", "w", stdout); 8 | int n; 9 | scanf("%d", &n); 10 | for(int i = 0; i < n; i++){ 11 | int exp; 12 | scanf("%d", &exp); 13 | while(exp >= 4){ 14 | exp-=4; 15 | } 16 | if(exp == 0){ 17 | printf("1\n"); 18 | }else if(exp == 1){ 19 | printf("7\n"); 20 | }else if(exp == 2){ 21 | printf("9\n"); 22 | }else if(exp == 3){ 23 | printf("3\n"); 24 | } 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Upsolving/URI/2633.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define S second 19 | #define PB push_back 20 | #define MP make_pair 21 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 22 | 23 | using namespace std; 24 | 25 | int main(){ 26 | 27 | 28 | // s = so + vt; 29 | 30 | /* 31 | 32 | L = ladrão G = guarda 33 | L G 34 | | / 35 | | / 36 | |/ 37 | Fronteira 38 | 39 | */ 40 | double d, vf, vg; 41 | while(cin >> d >> vf >> vg){ 42 | double hipotenusa = sqrt(d*d + 144); 43 | 44 | double sf = 12/vf; 45 | double sg = hipotenusa/vg; 46 | 47 | 48 | if(sg <= sf){ 49 | cout << "S" << endl; 50 | }else{ 51 | cout << "N" << endl; 52 | } 53 | } 54 | return 0; 55 | } -------------------------------------------------------------------------------- /Upsolving/URI/2717.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define S second 19 | #define PB push_back 20 | #define MP make_pair 21 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 22 | 23 | using namespace std; 24 | 25 | int main(){ 26 | int n; 27 | 28 | int c1, c2; 29 | 30 | cin >> n >> c1 >> c2; 31 | 32 | if(c1+c2 > n){ 33 | cout << "Deixa para amanha!\n"; 34 | }else{ 35 | cout << "Farei hoje!\n"; 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Upsolving/URI/2718.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Nome de Tipos 4 | typedef long long ll; 5 | typedef unsigned long long ull; 6 | typedef long double ld; 7 | 8 | // Valores 9 | #define INF 0x3F3F3F3F 10 | #define LINF 0x3F3F3F3F3F3F3F3FLL 11 | #define DINF (double)1e+30 12 | #define EPS (double)1e-9 13 | #define RAD(x) (double)(x*PI)/180.0 14 | #define PCT(x,y) (double)x*100.0/y 15 | 16 | // Atalhos 17 | #define F first 18 | #define S second 19 | #define PB push_back 20 | #define MP make_pair 21 | #define forn(i, n) for ( int i = 0; i < (n); ++i ) 22 | 23 | using namespace std; 24 | 25 | int main(){ 26 | long long n; 27 | 28 | cin >> n; 29 | 30 | forn(i, n){ 31 | long long x; 32 | 33 | cin >> x; 34 | 35 | string binary = bitset<50>(x).to_string(); 36 | 37 | long long maior = 0; 38 | 39 | forn(j, binary.size()){ 40 | long long contador = 0; 41 | while(j != binary.size() && binary[j] == '1'){ 42 | j++; 43 | contador++; 44 | } 45 | if(contador > maior){ 46 | maior = contador; 47 | } 48 | } 49 | 50 | cout << maior << endl; 51 | } 52 | 53 | return 0; 54 | } --------------------------------------------------------------------------------