本文整理汇总了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);
}
示例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;
}
示例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());
}
示例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);
}
示例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;
}
示例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());
}
示例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;
}
示例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
));
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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;
}
示例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;
}
示例15: HashSetExtensions_Max_ThrowsExceptionIfHashSetIsEmpty
public void HashSetExtensions_Max_ThrowsExceptionIfHashSetIsEmpty()
{
var set = new HashSet<Int32>();
set.Max();
}