Exemplo n.º 1
0
        private bool TryFindResultMoveGroups(BoxGroup currentUsed, List <MoveGroup> moveGroups)
        {
            var boxId = Array.FindIndex(BoxGroup.Elementary, it => !it.Intersects(currentUsed));

            if (boxId < 0 || boxId >= _k)
            {
                return(true);
            }

            foreach (var moveGroup in _moveGroups[boxId])
            {
                if (currentUsed.Intersects(moveGroup.BoxGroup))
                {
                    continue;
                }

                if (TryFindResultMoveGroups(currentUsed.Merge(moveGroup.BoxGroup), moveGroups))
                {
                    moveGroups.Add(moveGroup);
                    return(true);
                }
            }


            return(false);
        }
Exemplo n.º 2
0
        private BoxGroup FindSelfContainingBoxGroup(BoxGroup boxGroup, long startBoxNumber, long searchForNumber)
        {
            while (searchForNumber != startBoxNumber)
            {
                if (searchForNumber < int.MinValue || searchForNumber > int.MaxValue)
                {
                    return(BoxGroup.Empty);
                }

                if (!_numberToBoxMap.TryGetValue((int)searchForNumber, out var boxId))
                {
                    return(BoxGroup.Empty);
                }

                var newGroup = BoxGroup.Elementary[boxId];
                if (newGroup.Intersects(boxGroup))
                {
                    return(BoxGroup.Empty);
                }

                boxGroup        = boxGroup.Merge(newGroup);
                searchForNumber = _targetSum - (_boxes[boxId].Sum - searchForNumber);
            }

            return(boxGroup);
        }