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


C# SortedSet.Sum方法代码示例

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


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

示例1: Main

 static void Main(string[] args)
 {
     calc.GetAllPrimes_Atkin(100);
     SortedSet<ulong> goodNumbers = new SortedSet<ulong>();
     for (int n = 1; n < 51; n++)
     {
         for (int k = 0; k < n; k++)
         {
             if (IsSquareFree(n, k))
                 goodNumbers.Add(GetBinomialValue(n, k));
         }
     }
     Console.WriteLine(goodNumbers.Sum());
 }
开发者ID:balazsmolnar,项目名称:Euler,代码行数:14,代码来源:Program.cs

示例2: Main

    static void Main()
    {
        Console.Write("{0,-30}", "Enter number for subset sum:");
        int subSum = int.Parse(Console.ReadLine());

        Console.Write("{0,-30}", "Enter sub-set sequence:");
        int[] input = Console.ReadLine().Split(' ').Select(int.Parse).Distinct().ToArray();

        var unique = new List<SortedSet<int>>();

        bool noSubsets = true;
        int maskField = 1 << input.Length;
        for (int maskCount = 0; maskCount < maskField; maskCount++)
        {
            var subSet = new SortedSet<int>();
            for (int i = 0; i < input.Length; i++)
            {
                if ((maskCount & (1 << i)) > 0)
                {
                    subSet.Add(input[i]);
                }
            }
            if (subSet.Sum() == subSum && subSet.Count > 0)
            {
                noSubsets = false;
                unique.Add(subSet);
            }
        }

        unique.Sort((a, b) => (a.Count - b.Count));
        if (noSubsets)
        {
            Console.WriteLine("No matching subsets.");
        }
        else
        {
            foreach (var set in unique)
            {
                Console.WriteLine("{0} = {1}", string.Join(" + ",set), subSum);
            }
        }
    }
开发者ID:SoftUni-Fundamental,项目名称:01.Advanced-CSharp,代码行数:42,代码来源:SortedSubsetSum.cs

示例3: GetSumOfProductThatIsPandigital

        static int GetSumOfProductThatIsPandigital()
        {
            var list = new SortedSet<int>();

            for (int i = 1; i < 50; i++)
            {
                for (int j = 1; j < 2000; j++)
                {
                    if(HasSameDigitOrZero(i, j))
                        continue;
                    var product = i*j;
                    if(IsPandigital(i,j, product))
                    {

                        Console.Out.WriteLine(string.Format("got one ! i ={0} j = {1} product ={2}", i,j,product));
                        list.Add(product);
                    }
                }
            }

            return list.Sum();
        }
开发者ID:david--liu,项目名称:code_kata,代码行数:22,代码来源:Problem32.cs

示例4: HalfTriangleCountHeuristic

 public static double HalfTriangleCountHeuristic(IEnumerable<RenderItem> items, int dim, double x0, double x1, out double heuristicValue)
 {
     SortedSet<RenderItem> starts = new SortedSet<RenderItem>(items, new RenderItemDimStartComparator(dim));
     SortedSet<RenderItem> activeWindow = new SortedSet<RenderItem>(new RenderItemDimStopComparator(dim));
     heuristicValue = double.PositiveInfinity;
     double px = 0.5d*(x0+x1);
     double x, dummy;
     double leftsf = 0.0d;
     double rightsf = starts.Sum(item => item.Surface());
     double heu;
     double xe;
     int nl = 0x00;
     int nr = starts.Count;
     foreach(RenderItem ri in starts) {
         ri.GetDimensionBounds(dim, out x, out dummy);
         activeWindow.Add(ri);
         leftsf += ri.Surface();
         nl++;
         bool removed = true;
         while(activeWindow.Count > 0x00 && removed) {
             RenderItem min = activeWindow.Min;
             min.GetDimensionBounds(dim, out dummy, out xe);
             removed = xe <= x;
             if(removed) {
                 nr--;
                 rightsf -= ri.Surface();
                 activeWindow.Remove(min);
             }
         }
         heu = leftsf*nl+rightsf*nr;
         if(heu < heuristicValue && x0 < x && x < x1) {
             heuristicValue = heu;
             px = x;
         }
     }
     return px;
 }
开发者ID:KommuSoft,项目名称:MoRen,代码行数:37,代码来源:SplitDimensionHeuristics.cs


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