Heliocleg Posted August 3, 2023 Share Posted August 3, 2023 (edited) Pessoal boa noite, estou tentando montar conjuntos com 60 dezenas, usando conjuntos com 3 dezenas. Então fiz assim : usando os últimos 200 sorteios, contei as dezenas que sairam na 1ª posição do sorteio, até a 20ª posição. Separei as quatro que mais sairam em cada uma das posições e montei quatro conjuntos de 3 dezenas: CONJ : 1 2 3 4 POSI 1 : 1 2 3 | 1 2 4 | 1 3 4 | 2 3 4 | POSI 2 : 7 9 10 | 7 9 6 | 7 10 6 | 9 10 6 | POSI 3 : 11 14 19 | 11 14 12 | 11 19 12 | 14 19 12 | POSI 4 : 15 23 20 | 15 23 21 | 15 20 21 | 23 20 21 | POSI 5 : 24 29 26 | 24 29 18 | 24 26 18 | 29 26 18 | POSI 6 : 31 32 30 | 31 32 28 | 31 30 28 | 32 30 28 | POSI 7 : 34 36 35 | 34 36 27 | 34 35 27 | 36 35 27 | POSI 8 : 37 47 42 | 37 47 33 | 37 42 33 | 47 42 33 | POSI 9 : 46 38 51 | 46 38 45 | 46 51 45 | 38 51 45 | POSI 10 : 48 44 43 | 48 44 49 | 48 43 49 | 44 43 49 | POSI 11 : 55 59 56 | 55 59 50 | 55 56 50 | 59 56 50 | POSI 12 : 61 66 53 | 61 66 68 | 61 53 68 | 66 53 68 | POSI 13 : 70 60 72 | 70 60 65 | 70 72 65 | 60 72 65 | POSI 14 : 73 74 75 | 73 74 63 | 73 75 63 | 74 75 63 | POSI 15 : 76 69 78 | 76 69 67 | 76 78 67 | 69 78 67 | POSI 16 : 78 77 80 | 78 77 82 | 78 80 82 | 77 80 82 | POSI 17 : 79 81 87 | 79 81 83 | 79 87 83 | 81 87 83 | POSI 18 : 91 93 92 | 91 93 88 | 91 92 88 | 93 92 88 | POSI 19 : 95 94 98 | 95 94 90 | 95 98 90 | 94 98 90 | POSI 20 : 00 99 97 | 00 99 96 | 00 97 96 | 99 97 96 | Espero que não saiam do lugar... Quero montar os conjuntos assim : P1C1+P2C1+P3C1+P4C1+...+P19C1+P20C1 P1C1+P2C1+P3C1+P4C1+...+P19C1+P20C2 P1C1+P2C1+P3C1+P4C1+...+P19C1+P20C3 P1C1+P2C1+P3C1+P4C1+...+P19C1+P20C4 DEPOIS... P1C1+P2C1+P3C1+P4C1+...+P19C2+P20C1 P1C1+P2C1+P3C1+P4C1+...+P19C3+P20C1 P1C1+P2C1+P3C1+P4C1+...+P19C4+P20C1 E assim por diante : Ou seja a combinação de 20 conjuntos de 3 dezenas formando seq de 60 dez.. respeitando a posição... Faz 3 dias que estou tentando de vários jeitos (programação em c/c++), poram mais de 20 algoritmos diferentes... e nada de conseguir... Meu problema está na lógica dessa combinação... Alguém pode me ajudar com essa lógica ? ? ? Desde já agradeço ! ! ! Edited August 3, 2023 by Heliocleg 1 Quote Link to comment Share on other sites More sharing options...
PS_(Soares) Posted August 4, 2023 Share Posted August 4, 2023 #include <stdio.h> #define TOTAL_CONJUNTOS 20 #define DEZENAS_POR_CONJUNTO 3 #define TOTAL_DEZENAS (TOTAL_CONJUNTOS * DEZENAS_POR_CONJUNTO) // Função para imprimir uma combinação de 60 números void imprimir_combinacao(int combinacao[TOTAL_DEZENAS]) { for (int i = 0; i < TOTAL_DEZENAS; i++) { printf("%2d ", combinacao[i]); if ((i + 1) % DEZENAS_POR_CONJUNTO == 0) { printf("| "); } } printf("\n"); } // Função para gerar as combinações passo a passo void gerar_combinacoes(int conjunto[TOTAL_CONJUNTOS][DEZENAS_POR_CONJUNTO], int posicao) { if (posicao == TOTAL_DEZENAS) { imprimir_combinacao(conjunto[0]); return; } int conj, dez; for (conj = 0; conj < TOTAL_CONJUNTOS; conj++) { if (posicao < DEZENAS_POR_CONJUNTO) { conjunto[conj][posicao] = posicao + 1; gerar_combinacoes(conjunto, posicao + 1); } else { for (dez = conjunto[conj][posicao - DEZENAS_POR_CONJUNTO] + 1; dez <= TOTAL_DEZENAS; dez++) { conjunto[conj][posicao] = dez; gerar_combinacoes(conjunto, posicao + 1); } } } } int main() { int conjunto[TOTAL_CONJUNTOS][DEZENAS_POR_CONJUNTO]; printf("As combinacoes possiveis sao:\n"); gerar_combinacoes(conjunto, 0); return 0; } 2 Quote Link to comment Share on other sites More sharing options...
Bruno Cintra Posted August 4, 2023 Share Posted August 4, 2023 11 horas atrás, PS_(Soares) disse: #include <stdio.h> #define TOTAL_CONJUNTOS 20 #define DEZENAS_POR_CONJUNTO 3 #define TOTAL_DEZENAS (TOTAL_CONJUNTOS * DEZENAS_POR_CONJUNTO) // Função para imprimir uma combinação de 60 números void imprimir_combinacao(int combinacao[TOTAL_DEZENAS]) { for (int i = 0; i < TOTAL_DEZENAS; i++) { printf("%2d ", combinacao[i]); if ((i + 1) % DEZENAS_POR_CONJUNTO == 0) { printf("| "); } } printf("\n"); } // Função para gerar as combinações passo a passo void gerar_combinacoes(int conjunto[TOTAL_CONJUNTOS][DEZENAS_POR_CONJUNTO], int posicao) { if (posicao == TOTAL_DEZENAS) { imprimir_combinacao(conjunto[0]); return; } int conj, dez; for (conj = 0; conj < TOTAL_CONJUNTOS; conj++) { if (posicao < DEZENAS_POR_CONJUNTO) { conjunto[conj][posicao] = posicao + 1; gerar_combinacoes(conjunto, posicao + 1); } else { for (dez = conjunto[conj][posicao - DEZENAS_POR_CONJUNTO] + 1; dez <= TOTAL_DEZENAS; dez++) { conjunto[conj][posicao] = dez; gerar_combinacoes(conjunto, posicao + 1); } } } } int main() { int conjunto[TOTAL_CONJUNTOS][DEZENAS_POR_CONJUNTO]; printf("As combinacoes possiveis sao:\n"); gerar_combinacoes(conjunto, 0); return 0; } fala blz,vc manja bem de codigo c,c++ eu estou tentando modificar um codigo que não consegui fazer ,de gerar combinações C(N,K) mais não sequencial eu precisava que seja aleatorio,o codigo que tenho aqui até faz aleatorio mais com loop infinito,qualquer coisa te envio o codigo inteiro que faz combinações v,k,t,m=b igual o cologa. 1 Quote Link to comment Share on other sites More sharing options...
Heliocleg Posted August 4, 2023 Author Share Posted August 4, 2023 (edited) 19 horas atrás, PS_(Soares) disse: #include <stdio.h> #define TOTAL_CONJUNTOS 20 #define DEZENAS_POR_CONJUNTO 3 #define TOTAL_DEZENAS (TOTAL_CONJUNTOS * DEZENAS_POR_CONJUNTO) // Função para imprimir uma combinação de 60 números void imprimir_combinacao(int combinacao[TOTAL_DEZENAS]) { for (int i = 0; i < TOTAL_DEZENAS; i++) { printf("%2d ", combinacao[i]); if ((i + 1) % DEZENAS_POR_CONJUNTO == 0) { printf("| "); } } printf("\n"); } // Função para gerar as combinações passo a passo void gerar_combinacoes(int conjunto[TOTAL_CONJUNTOS][DEZENAS_POR_CONJUNTO], int posicao) { if (posicao == TOTAL_DEZENAS) { imprimir_combinacao(conjunto[0]); return; } int conj, dez; for (conj = 0; conj < TOTAL_CONJUNTOS; conj++) { if (posicao < DEZENAS_POR_CONJUNTO) { conjunto[conj][posicao] = posicao + 1; gerar_combinacoes(conjunto, posicao + 1); } else { for (dez = conjunto[conj][posicao - DEZENAS_POR_CONJUNTO] + 1; dez <= TOTAL_DEZENAS; dez++) { conjunto[conj][posicao] = dez; gerar_combinacoes(conjunto, posicao + 1); } } } } int main() { int conjunto[TOTAL_CONJUNTOS][DEZENAS_POR_CONJUNTO]; printf("As combinacoes possiveis sao:\n"); gerar_combinacoes(conjunto, 0); return 0; } BELEZA PS_(Soares) ! ! ! Vou implementar JÁ ! ! ! ! MUITO OBRIGADO ! ! ! Edited August 4, 2023 by Heliocleg 1 Quote Link to comment Share on other sites More sharing options...
Heliocleg Posted August 6, 2023 Author Share Posted August 6, 2023 PS_(Soares), o seu algoritmo funciona muito bem para um vetor, mas para uma matriz, infelizmente não... falta uma dimensão... a dos 4 conjuntos por posição no sorteio... Acho que teremos que usar a teoria de grafos... Quote Link to comment Share on other sites More sharing options...
Heliocleg Posted August 7, 2023 Author Share Posted August 7, 2023 (edited) Acho que resolvi ! ! ! Transformei a matriz em vetor... No vetor : do elemento 1 ao 4 : as 4 comb da posição 1. do elemento 5 ao 8 : as 4 comb da posição 2 do elemento 9 ao 12 : as 4 comb da posição 3 do elemento 13 ao 16 : as 4 comb da posição 4 e assim por diante até o elemento 80 posição 20. fiz a combinação com 20 loops. ( força bruta mesmo ! ) for ( ind[1]=1; ind[1]<=4; ind[1]++) { for ( ind[2]=5; ind[2]<=8; ind[2]++) { for ( ind[3]=9; ind[3]<=12; ind[3]++) { .... até ind[20]<=80 juntando os 3 elementos de cada índice, dando então 60 dez por comb... Ainda estou só gerando sem indexar para saber a quantidade total de comb e verificando se não tem dez repetida.. Vamos ver ! ! ! Edited August 7, 2023 by Heliocleg Quote Link to comment Share on other sites More sharing options...
Heliocleg Posted August 9, 2023 Author Share Posted August 9, 2023 Consegui montar as combinações do jeito postado acima... O problema agora é a quantidade de combinações... Pra se ter uma ideia só no IND[1]=1 (ainda faltam o 2, 3 e 4), criou 152 arquivos (não criou mais devido a falta de espaço no HD ! ) com 4.000.000 de combinações EM CADA UM... (608.000.000 combinações e contando...), só no IND[1]=1... Tentei então testar o primeiro arquivo criado (primeiras 4.000.000 de comb) para saber da performance delas em 2200 sorteios anteriores, ficou uma noite inteira e não acabou... ENTÃO DESISTI DESSE MÉTODO PARA CRIAR COMBINAÇÕES DE 60 DEZENAS COM MAIS DE 200 ACERTOS 20 EM 2200 SORTEIOS ! ! ! ! Ficou completamente INVIÁVEL ! ! ! Que pena ! ! ! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.