当前位置: 首页>>代码示例>>C#>>正文


C# HashSet.Max方法代码示例

本文整理汇总了C#中HashSet.Max方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.Max方法的具体用法?C# HashSet.Max怎么用?C# HashSet.Max使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HashSet的用法示例。


在下文中一共展示了HashSet.Max方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        HashSet<House> Houses = new HashSet<House>();
        long amountOfCable = 0;
        for (int i = 0; i < N; i++)
        {
            string[] inputs = Console.ReadLine().Split(' ');
            Houses.Add(new House { X = int.Parse(inputs[0]), Y = int.Parse(inputs[1]) });
        }

        //Core: Calculate Average House Y index
        double Avg = Houses.Sum(x => x.Y) / N;

        //Core:find the house closest to the Avg Y and use its Y coordinate
        int closest = Houses.OrderBy(x => Math.Abs(x.Y - Avg)).First().Y;

        //lay the mainline
        amountOfCable += (Houses.Max(x => x.X) - Houses.Min(x => x.X));

        //per other House calculate distance from location to mainline
        foreach (var i in Houses)
        {
            amountOfCable += i.Y > closest ? i.Y - closest : closest - i.Y;
        }

        // Write an action using Console.WriteLine()
        // To debug: Console.Error.WriteLine("Debug messages...");

        Console.WriteLine(amountOfCable);
    }
开发者ID:LievenVandeperre,项目名称:codinGame,代码行数:31,代码来源:10.+Network+Cabling.cs

示例2: BuildOddComposites

 HashSet<long> BuildOddComposites(HashSet<long> primes)
 {
     var oddComposites = new HashSet<long>();
       for (int i = 33; i < primes.Max(); i+=2) {
     if (!primes.Contains(i)) oddComposites.Add(i);
       }
       return oddComposites;
 }
开发者ID:asciamanna,项目名称:ProjectEuler,代码行数:8,代码来源:Problem46.cs

示例3: Main

        static void Main()
        {
            var collection = new HashSet<double> { 5.2, 8, -3.14, 0, 55 };

            Console.WriteLine(collection.Sum());
            Console.WriteLine(collection.Product());
            Console.WriteLine(collection.Min());
            Console.WriteLine(collection.Max());
            Console.WriteLine(collection.Average());
        }
开发者ID:danielkaradaliev,项目名称:TelerikAcademyAssignments,代码行数:10,代码来源:IEnumerableExtensionsMain.cs

示例4: FullRangeHit

        public void FullRangeHit(Int32 maximum)
        {
            var rolls = new HashSet<Int32>();
            while (LoopShouldStillRun() && rolls.Count < maximum)
                rolls.Add(Dice.Roll().d(maximum));

            Assert.That(rolls.Min(), Is.EqualTo(1));
            Assert.That(rolls.Max(), Is.EqualTo(maximum));
            Assert.That(rolls.Count, Is.EqualTo(maximum));
            Assert.Pass("Iterations: {0}", iterations);
        }
开发者ID:aloisdg,项目名称:RollGen,代码行数:11,代码来源:dTests.cs

示例5: Execute

        public override bool Execute()
        {
            if (Files == null || Files.Length == 0)
            {
                Log.LogError("Files argument must be specified");
                return false;
            }

            // remove files that should be skipped or don't have a version
            var filesToConsider = Files.Where(f => !f.GetMetadata("SkipVersionCheck").Equals("true", StringComparison.OrdinalIgnoreCase) &&
                                                   !String.IsNullOrEmpty(f.GetMetadata("AssemblyVersion")))
                                       .Select(f => new
                                       {
                                           File = f.ItemSpec,
                                           TargetPath = f.GetMetadata("TargetPath"),
                                           Version = new Version(f.GetMetadata("AssemblyVersion"))
                                       });

            var refFiles = filesToConsider.Where(f => f.TargetPath.StartsWith("ref", StringComparison.OrdinalIgnoreCase));

            HashSet<Version> permittedVersions = new HashSet<System.Version>();

            if (refFiles.Any())
            {
                foreach (var refFile in refFiles)
                {
                    permittedVersions.Add(refFile.Version);
                }

                // use the version of the higest reference assembly;
                Version = refFiles.Max(f => f.Version).ToString();
            }
            else
            {
                // no reference assemblies, permit any version
                foreach (var file in filesToConsider)
                {
                    permittedVersions.Add(file.Version);
                }

                Version = permittedVersions.Max().ToString();
            }

            foreach (var file in filesToConsider)
            {
                if (!permittedVersions.Contains(file.Version))
                {
                    Log.LogError("File {0} has version {1} which is inconsistent with other libs and doesn't match any reference assembly", file.File, file.Version);
                }
            }

            return !Log.HasLoggedErrors;
        }
开发者ID:TerabyteX,项目名称:buildtools,代码行数:53,代码来源:GetPackageVersion.cs

示例6: HotnessDetector

        public HotnessDetector(HashSet<double> allLatitudes, HashSet<double> allLongitudes)
        {
            // Get the entire list of waypoints within a single hunt
            // (or at least every latitude and longitude)
            // and determine the bounds of the playfield.

            // The playfield width is determined from the eastmost latitude
            // of the waypoints and the westmost latitude of the waypoints.
            // The playfield height is determined from the northernmost longitude
            // of the waypoints and the southernmost longitude of the waypoints.

            playfield = new GeoArea(allLongitudes.Min(), allLongitudes.Max(), allLatitudes.Max(), allLatitudes.Min());
        }
开发者ID:pgodwin,项目名称:AlleyCat,代码行数:13,代码来源:HotnessDetector.cs

示例7: Mex

 public static uint Mex(HashSet<uint> set)
 {
     if (!set.Any())
         return 0;
     //creepy implementation
     uint max = set.Max(), i = 0;
     for (; i <= max; i++)
     {
         if (!set.Contains(i))
             break;
     }
     return i;
 }
开发者ID:MarkiyanMatsekh,项目名称:SpragueGrundyTheory,代码行数:13,代码来源:Algorythm.cs

示例8: AddAnotherLocations

        public static void AddAnotherLocations(HashSet<Location> locs, int numberOfLocationsToAdd = 1)
        {
            var id = locs.Max(location => location.Id);

            for (int i = 0; i < numberOfLocationsToAdd; i++)
            {
                var longitude = 6 % (i + 1);
                var latitude = 6 % (i + 1);

                locs.Add(new Location
                (
                    latitude: latitude,
                    longitude: longitude
                ));
            }
        }
开发者ID:UnderNotic,项目名称:ShortPathAlg,代码行数:16,代码来源:LocationsForTesting.cs

示例9: IsPandigital

        private bool IsPandigital(long number)
        {
            var lenght = (int)Math.Log10(number) + 1;
            var digits = new HashSet<long>();

            while (number > 0)
            {
                var digit = number % 10;

                if (digit == 0)
                    return false;

                digits.Add(digit);

                number = number / 10;
            }

            return (digits.Count() == lenght) && digits.Max() == lenght;
        }
开发者ID:joeazbest,项目名称:Euler,代码行数:19,代码来源:Problem041.cs

示例10: Solve

        public long Solve()
        {
            var sum = 0;

            for (var number = 3; number <= 1000; number++)
            {
                var divisor = number * number;

                var remainders = new HashSet<int> { 2 };
                for (var n = 1; n <= 2 * number; n = n + 2)
                {
                    remainders.Add((2 * n * number) % divisor);
                }

                sum += remainders.Max();
            }

            return sum;
        }
开发者ID:joeazbest,项目名称:Euler,代码行数:19,代码来源:Problem120.cs

示例11: FindMinimumLatency

        public long FindMinimumLatency(string[] lines)
        {
            var graph = new Graph();
            graph.Parse(lines.Skip(2).ToArray());
            var clientVerticesLabels = lines[1].Split(' ');
            var clientVertices = new HashSet<Vertex>(clientVerticesLabels.Select(vertexLabel => graph[vertexLabel]));
            long minimumLatency = long.MaxValue;

            foreach (var currentVertex in graph.Vertices.Where(vertex => !clientVertices.Contains(vertex)))
            {
                var roadmap = graph.Dijkstra(currentVertex);
                var currentMinimumLatency = clientVertices.Max(x => roadmap[x].Distance);
                if (currentMinimumLatency < minimumLatency)
                {
                    minimumLatency = currentMinimumLatency;
                }
            }

            return minimumLatency;
        }
开发者ID:JustMeGaaRa,项目名称:Silent.Algorithms,代码行数:20,代码来源:gamsrv.cs

示例12: Migrate

        public void Migrate(IDocumentStore store, Assembly assemblyContainingMigrations, long toVersion = -1)
        {
            var migrationTypes = GetMigrationTypes(assemblyContainingMigrations);

            var toMax = toVersion < 0;

            if (!toMax) EnsureCanMigrate(toVersion, migrationTypes, assemblyContainingMigrations);
            if (migrationTypes.Count == 0) return;

            if (toMax) toVersion = long.MaxValue;
            using (var session = new IndexSavingDocumentSession(store.OpenSession()))
            {
                var txId = Guid.NewGuid();
                session.Advanced.DatabaseCommands.PromoteTransaction(txId);
                try
                {
                    var appliedMigrations = GetAppliedMigrations(store);
                    var appliedVersions = new HashSet<long>(appliedMigrations.Select(m => m.Version));
                    var currentMaxVersion = appliedVersions.Count == 0 ? 0 : appliedVersions.Max();

                    if (toVersion > currentMaxVersion)
                    {
                        MigrateUpTo(toVersion, appliedVersions, migrationTypes, session);
                    }
                    else
                    {
                        MigrateDownTo(toVersion, appliedMigrations, appliedVersions, migrationTypes, session);
                    }

                    session.SaveChanges();
                    session.Advanced.DatabaseCommands.Commit(txId);
                }
                catch
                {
                    session.RestoreIndexes();
                    session.Advanced.DatabaseCommands.Rollback(txId);
                    throw;
                }
            }
        }
开发者ID:andrewdavey,项目名称:ravendb-migrations,代码行数:40,代码来源:Migrator.cs

示例13: Solve

        public long Solve()
        {
            var primeUtil = new Prime(Limit);
            var numbers = new HashSet<long>();

            foreach (var prime in primeUtil.PrimeList)
            {
                if (prime < Limit)
                    numbers.Add(prime + 1);
            }

            Console.WriteLine(numbers.Count);
            Console.WriteLine(numbers.Max());

            var factorization = new Dictionary<long, Dictionary<long, long>>();
            foreach (var number in numbers)
            {
                factorization.Add(number, primeUtil.GetDecomposition(number));
            }

            Console.WriteLine("Faktorizace Done");

            return 0;
        }
开发者ID:joeazbest,项目名称:Euler,代码行数:24,代码来源:Problem518.cs

示例14: Collapse


//.........这里部分代码省略.........
                                .Where(output => output.Item3.Item2 == outerNode)
                                .Select(
                                    output =>
                                    new
                                    {
                                        InnerNodeInputSender = output.Item1,
                                        OuterNodeInPortData = output.Item3.Item1
                                    }).ToList();

                            nodeInputs.ForEach(_ => node.AddInput());

                            node.RegisterAllPorts();

                            return new
                            {
                                OuterNode = outerNode,
                                InnerNode = node,
                                Outputs = inputs.Where(input => input.Item3.Item2 == outerNode)
                                                .Select(input => input.Item3.Item1),
                                Inputs = nodeInputs,
                                OuterNodePortDataList = inPortsConnected
                            };
                        }).ToList();

            #endregion

            #region UI Positioning Calculations

            double avgX = selectedNodeSet.Average(node => node.X);
            double avgY = selectedNodeSet.Average(node => node.Y);

            double leftMost = selectedNodeSet.Min(node => node.X);
            double topMost = selectedNodeSet.Min(node => node.Y);
            double rightMost = selectedNodeSet.Max(node => node.X + node.Width);

            #endregion

            #region Move selection to new workspace

            var connectors = new HashSet<ConnectorModel>(currentWorkspace.Connectors.Where(
                                                                conn => selectedNodeSet.Contains(conn.Start.Owner)
                                                                    && selectedNodeSet.Contains(conn.End.Owner)));

            //Step 2: move all nodes to new workspace
            //  remove from old
            foreach (var ele in selectedNodeSet)
            {
                ele.SaveResult = false;
                currentWorkspace.Nodes.Remove(ele);
                ele.WorkSpace = newNodeWorkspace;
            }
            foreach (var ele in connectors)
            {
                currentWorkspace.Connectors.Remove(ele);
            }

            //  add to new
            newNodeWorkspace.Nodes.AddRange(selectedNodeSet);
            newNodeWorkspace.Connectors.AddRange(connectors);

            double leftShift = leftMost - 250;
            foreach (NodeModel node in newNodeWorkspace.Nodes)
            {
                node.X = node.X - leftShift;
                node.Y = node.Y - topMost;
            }
开发者ID:kscalvin,项目名称:Dynamo,代码行数:67,代码来源:NodeCollapser.cs

示例15: HashSetExtensions_Max_ThrowsExceptionIfHashSetIsEmpty

        public void HashSetExtensions_Max_ThrowsExceptionIfHashSetIsEmpty()
        {
            var set = new HashSet<Int32>();

            set.Max();
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:6,代码来源:HashSetExtensionsTest.cs


注:本文中的HashSet.Max方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。