Example #1
0
 private static void LerSaloes(CasoDeTeste _teste)
 {
     for (int i = 1; i <= _teste.NumeroSalao; i++)
     {
         _teste.Saloes.Add(new Salao(i));
     }
 }
Example #2
0
 private static void LerMagias(string[] linhas, ref int linhaCont, CasoDeTeste _teste)
 {
     for (int i = 0; i < _teste.NumeroMagia; i++)
     {
         string[] linha  = linhas[++linhaCont].Split(' ');
         Magia    _magia = new Magia(int.Parse(linha[0]), int.Parse(linha[1]));
         _teste.Goku.Magias.Add(_magia);
     }
 }
Example #3
0
        static public int[,] PreencherTabelaDinamica(CasoDeTeste casoDeTeste)
        {
            if (casoDeTeste == null || casoDeTeste.Goku == null || casoDeTeste.Goku.Magias == null || casoDeTeste.Goku.Magias.Count == 0)
            {
                return(null);
            }

            int[,] tabela;
            List <Magia> magiasOrdenadas  = QuickSort.MetodoQuickSort(casoDeTeste.Goku.Magias);
            int          maiorVidaMonstro = int.MinValue;

            maiorVidaMonstro = casoDeTeste.getMaiorVidaMonstro();
            if (maiorVidaMonstro == int.MinValue)
            {
                maiorVidaMonstro = 0;
                tabela           = new int[casoDeTeste.Goku.Magias.Count, maiorVidaMonstro + 1];
            }
            else
            {
                tabela = new int[casoDeTeste.Goku.Magias.Count, maiorVidaMonstro + 1];
            }

            for (int i = 0; i < tabela.GetLength(0); i++)
            {
                for (int j = 0; j < tabela.GetLength(1); j++)
                {
                    if (i == 0)
                    {
                        int dano = 0;
                        while (dano < j)
                        {
                            dano         += magiasOrdenadas[i].Dano;
                            tabela[i, j] += magiasOrdenadas[i].Ki;
                        }
                    }
                    else if (j < magiasOrdenadas[i].Dano)
                    {
                        tabela[i, j] = tabela[i - 1, j];
                    }
                    else
                    {
                        tabela[i, j] = Math.Min(tabela[i - 1, j], tabela[i, j - magiasOrdenadas[i].Dano] + magiasOrdenadas[i].Ki);
                    }
                }
            }

            return(tabela);
        }
Example #4
0
 private static void LerMonstros(string[] linhas, ref int linhaCont, CasoDeTeste _teste)
 {
     for (int i = 0; i < _teste.NumeroMonstro; i++)
     {
         string[] linha  = linhas[++linhaCont].Split(' ');
         Salao    _salao = null;
         _teste.Saloes.ForEach(s =>
         {
             if (s.NumeroSalao == int.Parse(linha[0]))
             {
                 _salao = s;
             }
         });
         Monstro _monstro = new Monstro(_salao, int.Parse(linha[1]));
         _salao.Monstros.Add(_monstro);
     }
 }
Example #5
0
        private static void CriarObjetos(string[] linhas)
        {
            int linhaCont = -1;

            do
            {
                string[]    linha  = linhas[++linhaCont].Split(' ');
                CasoDeTeste _teste = new CasoDeTeste(int.Parse(linha[0]), int.Parse(linha[1]), int.Parse(linha[2]), int.Parse(linha[3]));
                if (_teste.NumeroGaleria == 0 && _teste.NumeroMagia == 0 && _teste.NumeroMonstro == 0 && _teste.NumeroSalao == 0)
                {
                    break;
                }
                LerMagias(linhas, ref linhaCont, _teste);
                LerSaloes(_teste);
                LerGalerias(linhas, ref linhaCont, _teste);
                LerMonstros(linhas, ref linhaCont, _teste);
                Estruturas.Casos.Add(_teste);
            } while (linhaCont < linhas.Length);
        }
Example #6
0
 private static void LerGalerias(string[] linhas, ref int linhaCont, CasoDeTeste _teste)
 {
     for (int i = 0; i < _teste.NumeroGaleria; i++)
     {
         string[] linha = linhas[++linhaCont].Split(' ');
         Salao    _salao1 = null, _salao2 = null;
         _teste.Saloes.ForEach(s =>
         {
             if (s.NumeroSalao == int.Parse(linha[0]))
             {
                 _salao1 = s;
             }
             else if (s.NumeroSalao == int.Parse(linha[1]))
             {
                 _salao2 = s;
             }
         });
         Galeria _galeria = new Galeria(_salao1, _salao2);
         _salao1.Galeria.Add(_galeria);
         _salao2.Galeria.Add(_galeria);
         _teste.Galerias.Add(_galeria);
     }
 }
Example #7
0
        private void Djikstra(CasoDeTeste teste, out int melhorKi, string metodo)
        {
            Salao origem = teste.Saloes[0];
            List <List <Salao> > caminho = new List <List <Salao> >();
            List <int>           gastoKi = new List <int>();

            melhorKi = 0;
            int[,] tabelaDinamica = new int[0, 0];
            if (metodo == "DN")
            {
                tabelaDinamica = Estruturas.PreencherTabelaDinamica(teste);
            }

            for (int i = 0; i < teste.Saloes.Count; i++)
            {
                gastoKi.Add(int.MaxValue);
                caminho.Add(new List <Salao>());
            }

            gastoKi[0] = 0;

            while (true)
            {
                Salao selecionado  = null;
                int   menorGastoKi = int.MaxValue;
                for (int i = 0; i < gastoKi.Count; i++)
                {
                    if (menorGastoKi >= gastoKi[i] && !teste.Saloes[i].visitado)
                    {
                        menorGastoKi = gastoKi[i];
                        selecionado  = teste.Saloes[i];
                    }
                }
                if (selecionado == null)
                {
                    break;
                }
                selecionado.visitado = true;
                selecionado.Galeria.ForEach(galeria =>
                {
                    Salao vizinho;
                    if (galeria.Salao1 == selecionado)
                    {
                        vizinho = galeria.Salao2;
                    }
                    else
                    {
                        vizinho = galeria.Salao1;
                    }
                    if (!vizinho.visitado)
                    {
                        int indexVizinho     = teste.Saloes.IndexOf(vizinho);
                        int indexSelecionado = teste.Saloes.IndexOf(selecionado);
                        if (gastoKi[indexSelecionado] + teste.Saloes[indexSelecionado].Combate(teste.Goku, tabelaDinamica, metodo) < gastoKi[indexVizinho])
                        {
                            gastoKi[indexVizinho] = gastoKi[indexSelecionado] + teste.Saloes[indexSelecionado].Combate(teste.Goku, tabelaDinamica, metodo);
                            caminho[indexVizinho] = caminho[indexSelecionado];
                            caminho[indexVizinho].Add(teste.Saloes[indexVizinho]);
                            teste.Saloes[indexSelecionado].visitado = true;
                        }
                    }
                });

                bool verticesNaoVisitados = false;
                for (int i = 0; i < teste.Saloes.Count; i++)
                {
                    if (!teste.Saloes[i].visitado)
                    {
                        verticesNaoVisitados = true;
                    }
                }

                if (!verticesNaoVisitados)
                {
                    break;
                }

                selecionado = null;
            }

            melhorKi = gastoKi[teste.Saloes.Count - 1];
        }