Esempio n. 1
0
        }                                              ///@property(readwrite,assign) PondType type;

        public void AddToScene(PondInfo info)
        {
            position       = info.position;
            radius         = info.radius - 7;
            radiusSqr      = radius * radius;
            type           = info.type;
            timeSinceSplat = 0.0f;
        }
Esempio n. 2
0
        public int Trap(int[] height)
        {
            var      stack = new Stack <PondInfo>();
            PondInfo lastInStack = null, current;

            for (int i = 0, currentLandArea; i < height.Length; ++i)
            {
                current = new PondInfo()
                {
                    Height = height[i], Pos = i
                };
                if (stack.Count == 0 || stack.Peek().Height > height[i])
                {
                    stack.Push(current);
                }
                else
                {
                    currentLandArea = 0;
                    while (stack.Count > 0 && stack.Peek().Height <= height[i])
                    {
                        currentLandArea += stack.Peek().Land + stack.Peek().Height;
                        lastInStack      = stack.Pop();
                    }
                    if (stack.Count == 0)
                    {
                        current.Water = lastInStack.Water + lastInStack.Height * (current.Pos - lastInStack.Pos) - currentLandArea;
                    }
                    else
                    {
                        current.Land  = currentLandArea;
                        current.Water = current.Height * (current.Pos - stack.Peek().Pos - 1) - currentLandArea;
                    }
                    stack.Push(current);
                }
            }
            int totalWater = 0;

            while (stack.Count > 0)
            {
                lastInStack = stack.Pop();
                totalWater += lastInStack.Water;
            }
            return(totalWater);
        }