public IEnemy[] GetOrderedByHealth()
        {
            var newLegion = new OrderedSet <IEnemy>(CompareElements);

            newLegion.AddMany(this.legion);
            return(newLegion.ToArray());
        }
        /// <summary>
        /// Tests whether a <see cref="IGeometry" /> is sequenced correctly.
        /// <see cref="ILineString" />s are trivially sequenced.
        /// <see cref="IMultiLineString" />s are checked for correct sequencing.
        /// Otherwise, <c>IsSequenced</c> is defined
        /// to be <c>true</c> for geometries that are not lineal.
        /// </summary>
        /// <param name="geom">The <see cref="IGeometry" /> to test.</param>
        /// <returns>
        /// <value>true</value> if the <see cref="IGeometry" /> is sequenced or is not lineal.
        /// </returns>
        public static bool IsSequenced(IGeometry geom)
        {
            if (!(geom is IMultiLineString))
            {
                return(true);
            }

            IMultiLineString mls = geom as IMultiLineString;

            // The nodes in all subgraphs which have been completely scanned
            OrderedSet <Coordinate> prevSubgraphNodes = new OrderedSet <Coordinate>();

            Coordinate         lastNode  = null;
            IList <Coordinate> currNodes = new List <Coordinate>();

            for (int i = 0; i < mls.NumGeometries; i++)
            {
                ILineString line      = (ILineString)mls.GetGeometryN(i);
                Coordinate  startNode = line.GetCoordinateN(0);
                Coordinate  endNode   = line.GetCoordinateN(line.NumPoints - 1);

                /*
                 * If this linestring is connected to a previous subgraph, geom is not sequenced
                 */
                if (prevSubgraphNodes.Contains(startNode))
                {
                    return(false);
                }
                if (prevSubgraphNodes.Contains(endNode))
                {
                    return(false);
                }

                if (lastNode != null && !startNode.Equals(lastNode))
                {
                    // start new connected sequence
                    prevSubgraphNodes.AddMany(currNodes);
                    currNodes.Clear();
                }

                currNodes.Add(startNode);
                currNodes.Add(endNode);
                lastNode = endNode;
            }
            return(true);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var linesCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < linesCount; i++)
            {
                var line     = Console.ReadLine();
                var ocurDict = new Dictionary <char, int>();

                // adding connections
                for (int j = 0; j < line.Length; j++)
                {
                    var ch = line[j];

                    ocurDict[ch] = ocurDict.ContainsKey(ch) ? ocurDict[ch] + 1 : 1;

                    if (!graph.ContainsKey(ch))
                    {
                        graph.Add(ch, new SortedSet <char>());
                    }
                }

                foreach (var kv in ocurDict)
                {
                    occurs[kv.Key] = occurs.ContainsKey(kv.Key) ? Math.Max(occurs[kv.Key], ocurDict[kv.Key]) : ocurDict[kv.Key];
                }
            }

            var bag = new OrderedSet <char>(startElements.Difference(endElements));

            while (bag.Count > 0)
            {
                var nextQueue = new OrderedSet <char>();
                foreach (var nextPoint in bag)
                {
                    allAnswers.Add(nextPoint);
                    nextQueue.AddMany(graph[nextPoint]);
                }

                bag = nextQueue;
            }

            Console.WriteLine(string.Join("", allAnswers));
        }
Esempio n. 4
0
        /// <summary>
        /// Tests whether a <see cref="Geometry" /> is sequenced correctly.
        /// <see cref="LineString" />s are trivially sequenced.
        /// <see cref="MultiLineString" />s are checked for correct sequencing.
        /// Otherwise, <c>IsSequenced</c> is defined
        /// to be <c>true</c> for geometries that are not lineal.
        /// </summary>
        /// <param name="geom">The <see cref="Geometry" /> to test.</param>
        /// <returns>
        /// <c>true</c> if the <see cref="Geometry" /> is sequenced or is not lineal.
        /// </returns>
        public static bool IsSequenced(IGeometry geom)
        {
            if (!(geom is IMultiLineString)) 
                return true;
        
            IMultiLineString mls = geom as IMultiLineString;

            // The nodes in all subgraphs which have been completely scanned
            OrderedSet<ICoordinate> prevSubgraphNodes = new OrderedSet<ICoordinate>();

            ICoordinate lastNode = null;
            IList<ICoordinate> currNodes = new List<ICoordinate>();
            for (int i = 0; i < mls.NumGeometries; i++) 
            {
                ILineString line = (ILineString) mls.GetGeometryN(i);
                ICoordinate startNode = line.GetCoordinateN(0);
                ICoordinate endNode   = line.GetCoordinateN(line.NumPoints - 1);

                /*
                 * If this linestring is connected to a previous subgraph, geom is not sequenced
                 */
                if (prevSubgraphNodes.Contains(startNode)) 
                    return false;
                if (prevSubgraphNodes.Contains(endNode)) 
                    return false;

                if (lastNode != null && startNode != lastNode) 
                {
                    // start new connected sequence
                    prevSubgraphNodes.AddMany(currNodes);
                    currNodes.Clear();
                }                

                currNodes.Add(startNode);
                currNodes.Add(endNode);
                lastNode = endNode;
            }
            return true;
        }