Esempio n. 1
0
        private static MinMaxPair GetNextPair(MinMaxPair pair, int element)
        {
            pair.MinElement = Math.Min(pair.MinElement, element);
            pair.MaxElement = Math.Max(pair.MaxElement, element);

            return(new MinMaxPair()
            {
                MinElement = pair.MinElement,
                MaxElement = pair.MaxElement
            });
        }
Esempio n. 2
0
        private static MinMaxPair GetNextPair(MinMaxPair pair, int element)
        {
            pair.MinElement = Math.Min(pair.MinElement, element);
            pair.MaxElement = Math.Max(pair.MaxElement, element);

            return new MinMaxPair()
            {
                MinElement = pair.MinElement,
                MaxElement = pair.MaxElement
            };
        }
Esempio n. 3
0
        private static void FindMinimumSolvedProblems(int variety, int[] pleasentnessNumbers, int startIndex)
        {
            var resultIndex = 0;

            var currentVarieties = new MinMaxPair[pleasentnessNumbers.Length];

            currentVarieties[startIndex] = new MinMaxPair()
            {
                MinElement = pleasentnessNumbers[startIndex],
                MaxElement = pleasentnessNumbers[startIndex]
            };

            for (int i = startIndex; i < pleasentnessNumbers.Length - 2; i++)
            {
                var nextElement     = pleasentnessNumbers[i + 1];
                var nextNextElement = pleasentnessNumbers[i + 2];

                var nextPair     = GetNextPair(currentVarieties[i], nextElement);
                var nextNextPair = GetNextPair(currentVarieties[i], nextNextElement);

                if (nextPair.Variety > nextNextPair.Variety)
                {
                    currentVarieties[i + 1] = nextPair;
                    resultIndex             = i + 1;
                }
                else
                {
                    currentVarieties[i + 1] = nextNextPair;
                    resultIndex             = i + 2;
                }

                if (currentVarieties[i + 1].Variety >= variety)
                {
                    minimumResult = Math.Min(minimumResult, ((resultIndex + 3) / 2));
                    break;
                }
            }
        }
Esempio n. 4
0
        private static void FindMinimumSolvedProblems(int variety, int[] pleasentnessNumbers, int startIndex)
        {
            var resultIndex = 0;

            var currentVarieties = new MinMaxPair[pleasentnessNumbers.Length];
            currentVarieties[startIndex] = new MinMaxPair()
            {
                MinElement = pleasentnessNumbers[startIndex],
                MaxElement = pleasentnessNumbers[startIndex]
            };

            for (int i = startIndex; i < pleasentnessNumbers.Length - 2; i++)
            {
                var nextElement = pleasentnessNumbers[i + 1];
                var nextNextElement = pleasentnessNumbers[i + 2];

                var nextPair = GetNextPair(currentVarieties[i], nextElement);
                var nextNextPair = GetNextPair(currentVarieties[i], nextNextElement);

                if (nextPair.Variety > nextNextPair.Variety)
                {
                    currentVarieties[i + 1] = nextPair;
                    resultIndex = i + 1;
                }
                else
                {
                    currentVarieties[i + 1] = nextNextPair;
                    resultIndex = i + 2;
                }

                if (currentVarieties[i + 1].Variety >= variety)
                {
                    minimumResult = Math.Min(minimumResult, ((resultIndex + 3) / 2));
                    break;
                }
            }
        }