Ejemplo n.º 1
0
 public CAxe(
     CSegmentSquad inSquad)
 {
     _squad           = inSquad;
     _pointCage       = new CPoint[3];
     _pointCageSize   = 0;
     _remainingForAxe = 3;
 }
Ejemplo n.º 2
0
        public int Solve(int[] input)
        {
            // Implement your solution here, and return the correct result instead of 0

            int theResult = 0;

            if (input.Length < 5)
            {
                return(0);
            }

            Array.Sort(input);
            foreach (int i in input)
            {
                Console.Write(i + " ");
            }

            CPoint.SetBackingArray(input);
            CSegmentSquad theSegmentSquad = new CSegmentSquad(input);

            for (int i = 0; i < input.Length;)
            {
                bool canRecruit = theSegmentSquad.Recruit(ref i);
            }
            bool isFeasible = theSegmentSquad.FinalizeRecruit();

            if (!isFeasible)
            {
                return(0);
            }

            CAxe theAxe = new CAxe(theSegmentSquad);

            theSegmentSquad.Arm();

            CSegmentPool theMinimals    = theSegmentSquad.GetMinimals();
            CSegmentPool theSubMinimals = theSegmentSquad.GetSubMinimals();
            CSegmentPool thePool        = theMinimals;

            while (theAxe.CanAttack())
            {
                if (!theAxe.Attack(thePool))
                {
                    break;
                }

                if (thePool == theMinimals)
                {
                    if (theSubMinimals.GetMinDist() < thePool.GetMinDist())
                    {
                        thePool = theSubMinimals;
                    }
                }
                else
                {
                    if (theMinimals.GetMinDist() < theSubMinimals.GetMinDist())
                    {
                        thePool = theMinimals;
                    }
                }
            }

            if (theSegmentSquad.Disarmed())
            {
                CPoint[] theCage = theAxe.GetCage();
                foreach (var thePoint in theCage)
                {
                    theResult += Math.Abs(thePoint.Value);
                }
            }

            return(theResult);
        }